This discussion is archived
6 Replies Latest reply: Feb 26, 2012 8:02 AM by Steve_Clamage RSS

sunCC chokes on inline assembler (boost 1.49 compilation)

919808 Newbie
Currently Being Moderated
Hello.

In my quest to get a project compiled which depends on boost (amongst others), I tried to compile boost 1.49. After small modifications, the compile went peacefully but sunCC chokes on some assembler which is unfortunately required for parts that the project depends on.

Here is a small testcase. The atomic_add32() is taken straight from boost. What is interesting though is that if no -xO flag is set, sunCC compiles without any warnings/errors but seems to ignore the assembler because it produces the wrong output (5 instead of 30). As soon as a -xO[0-5] is set, the following error is produced: "test.cpp", [main]:ube: error: Invalid reference to argument '0' in GASM Inlining

Again, I am using a x86_64 Linux (Gentoo) with Studio 12.3 and gcc 4.6.2 (if that matters). Naturally, gcc/icc/path64 all compile is code just fine and produce the right result.

-----
#include <stdint.h>
#include <iostream>

inline uint32_t atomic_add32(volatile uint32_t *mem, uint32_t val)
{
int r;

asm volatile
(
"lock\n\t"
"xadd %1, %0":
"+m"( *mem ), "=r"( r ): // outputs (%0, %1)
"1"( val ): // inputs (%2 == %1)
"memory", "cc" // clobbers
);

return r;
}

int main(void)
{
uint32_t test = 5;

atomic_add32(&test, 25);

std::cout << test << std::endl;

return 0;
}
-----

Thanks for any help in advance.

So long,
matthias
  • 1. Re: sunCC chokes on inline assembler (boost 1.49 compilation)
    SFV Newbie
    Currently Being Moderated
    >
    As soon as a -xO[0-5] is set, the following error is produced: "test.cpp", [main]:ube: error: Invalid reference to argument '0' in GASM Inlining
    Without optimisation compiler runs a "simple" code generator, which is know to have issues with gnu-inline-asm.
    With -O0+ compiler runs a different backend (named UBE).
    It has much better support for gnu-inline-asm, though you seem to have hit a bug in it.
    The atomic_add32() is taken straight from boost.
    What library it comes from?
    I did not see these hiccups on intel Solaris, and this particular part of the compiler is not platform specific (Linux should not differ to Solaris).

    regards
    __Fedor.
  • 2. Re: sunCC chokes on inline assembler (boost 1.49 compilation)
    SFV Newbie
    Currently Being Moderated
    The atomic_add32() is taken straight from boost.
    I did not see these hiccups on intel Solaris, and this particular part of the compiler is not platform specific (Linux should not differ to Solaris).
    Well, it appears I was wrong here.
    The header boost/interprocess/detail/atomic.hpp is very platform/compiler specific and it uses Solaris' atomic interface on Solaris :(

    Btw, did you enable __GNUC__ to get it working through gnu-asm?

    regards,
    __Fedor.

    Edited by: SFV on Feb 25, 2012 1:22 PM
  • 3. Re: sunCC chokes on inline assembler (boost 1.49 compilation)
    919808 Newbie
    Currently Being Moderated
    Yes, unfortunately that part is rather specific. Once C++11 reaches all compilers, we will have native atomic support and things like this will finally be history. :)

    To be honest, no, I did not define __GNUC__ but simply modified the atomic.hpp slightly so it would use that particular implementation because I saw no reason for it to not work or be dangerous in any way and I did not want to define __GNUC__ globally because I am not that familiar yet with sunCC to grasp all repercussion it might have. So i opted for the former solution.

    Am I right with my assumption that for unsupported systems, no patches or anything alike are provided? Meaning in this case, if this bug gets fixed, I will have to wait for an eventual Studio 12.4 because the Express line seems to be discontinued. :( Which brings me to my next questions: Is there any chance this gets fixed anytime soon(ish)?

    Thanks for your swift response.

    So long
    matthias

    Edited by: khaos on Feb 25, 2012 11:58 AM
  • 4. Re: sunCC chokes on inline assembler (boost 1.49 compilation)
    SFV Newbie
    Currently Being Moderated
    Am I right with my assumption that for unsupported systems, no patches or anything alike are provided?
    If this bug gets fixed, I will have to wait for an eventual Studio 12.4
    Yes, thats true.
    Nowadays we do patches only through the official support channels... :-\
    Is there any chance this gets fixed anytime soon(ish)?
    The only chance for you (unless you dont have an official support contract) to get over it is to modify this gnu-asm a bit so UBE does not choke over it.
    I will ask UBE team for an exact workaround.

    regards,
    __Fedor.
  • 5. Re: sunCC chokes on inline assembler (boost 1.49 compilation)
    919808 Newbie
    Currently Being Moderated
    Nowadays we do patches only through the official support channels... :-\
    Pity, really. That pretty much disqualifies the use of this compiler for several use cases.
    The only chance for you (unless you dont have an official support contract) to get over it is to modify this gnu-asm a bit so UBE does not choke over it.
    I will ask UBE team for an exact workaround.
    Thanks.

    Just one more quick question: There are no more releases for the Express edition? And the standard Oracle Solaris Studio is released more like annually? That means, a serious bug which has a patch available through the official support channels, can keep you biting for 12 months in the worst case?

    So long
    matthias
  • 6. Re: sunCC chokes on inline assembler (boost 1.49 compilation)
    Steve_Clamage Pro
    Currently Being Moderated
    The Express releases are Beta versions. The Express and official releases of Studio are free for download and use.

    Once the official release has occurred, Oracle policy, unlike the former Sun policy, is to provide patches for that release only via a support contract. So, yes, since Studio 12.3 has been officially released, if you run into a bug, your choices are to work around the bug, get a service contract, or wait until the next release.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points