[Bug target/78357] nios2 uses non-standard atomic functions

cltang at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Nov 15 15:43:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78357

--- Comment #9 from Chung-Lin Tang <cltang at gcc dot gnu.org> ---
(In reply to Sebastian Huber from comment #8)
> (In reply to Chung-Lin Tang from comment #7)
> > (In reply to Sebastian Huber from comment #6)
> > > (In reply to Chung-Lin Tang from comment #5)
> > > > > I checked the code generation on some targets for the test case above. The
> > > > > arm, bfin, epiphany, i386, lm32, m68k, mips, moxie, sh, v850 targets
> > > > > generated all __atomic_* functions.
> > > > 
> > > > > Only on Nios II it seems, the other targets emit __atomic_* calls.
> > > > 
> > > > Many of those target archs use __sync_* by default on Linux, although you
> > > > might generate __atomic_* on bare metal.
> > > > That's the case on nios2; we should be generating __atomic_* calls if you're
> > > > using nios2 ELF (bare metal), for Linux the compiler will generate __sync_*
> > > > calls, unless the architecture has hardware instructions.
> > > 
> > > This sounds reasonable.  Which magic switch in GCC leads to the generation
> > > of __sync_* functions instead of __atomic_* functions?
> > 
> > You can use -fno-sync-libcalls to force OFF __sync_* and generate __atomic_*
> > calls,
> > if that's really what you want (although we have not implemented that kind
> > of runtime support).
> 
> Ok, thanks for the hint. Now I know where the problem is really. In
> "gcc/config/rtems.h" we define TARGET_LINUX_ABI to enable the TLS support
> for RTEMS. This is due to (nios2.c):
> 
> #undef TARGET_HAVE_TLS
> #define TARGET_HAVE_TLS TARGET_LINUX_ABI
> 
> We also have:
> 
> /* Implement TARGET_INIT_LIBFUNCS.  */
> static void
> nios2_init_libfuncs (void)
> {
>   /* For Linux, we have access to kernel support for atomic operations.  */
>   if (TARGET_LINUX_ABI)
>     init_sync_libfuncs (UNITS_PER_WORD);
> }
> 
> Would it be possible to add an alternative way to enable TLS support for
> RTEMS? For example:
> 
> #ifndef TARGET_HAVE_TLS
> #define TARGET_HAVE_TLS TARGET_LINUX_ABI
> #endif
> 
> Then use in rtems.h:
> 
> #define TARGET_HAVE_TLS 1

I think I know what you need, I submit a patch later.


More information about the Gcc-bugs mailing list