This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/78357] nios2 uses non-standard atomic functions
- From: "sebastian dot huber at embedded-brains dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 15 Nov 2016 14:53:20 +0000
- Subject: [Bug target/78357] nios2 uses non-standard atomic functions
- Auto-submitted: auto-generated
- References: <bug-78357-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78357
--- Comment #8 from Sebastian Huber <sebastian.huber@embedded-brains.de> ---
(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