public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Providing C level symbols via linker scripts
@ 2006-03-21 15:00 Will Newton
  2006-03-21 17:09 ` Dave Korn
  2006-03-21 18:50 ` Mike Frysinger
  0 siblings, 2 replies; 4+ messages in thread
From: Will Newton @ 2006-03-21 15:00 UTC (permalink / raw)
  To: binutils


Hi all,

I maintain an as yet unreleased binutils port for an architecture that
prepends an underscore to symbol names defined in C (for legacy
reasons). This is normally not a problem, but some software e.g. uClibc
wishes to reference symbols defined in the linker scripts such as
__init_array_start, but because they are referenced in C the symbol
referenced is actually ___init_array_start (i.e. 3 leading underscores
rather than 2). This results in an undefined symbol at link time.
Obviously I can hack the uClibc code to get the right symbol, but I was
wondering if there was a better solution to this problem? Do other
architectures have this problem e.g. sh?

Thanks,

(apologies for the excessive footer)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Providing C level symbols via linker scripts
  2006-03-21 15:00 Providing C level symbols via linker scripts Will Newton
@ 2006-03-21 17:09 ` Dave Korn
  2006-03-21 20:40   ` Mike Frysinger
  2006-03-21 18:50 ` Mike Frysinger
  1 sibling, 1 reply; 4+ messages in thread
From: Dave Korn @ 2006-03-21 17:09 UTC (permalink / raw)
  To: 'Will Newton', binutils

On 21 March 2006 14:27, Will Newton wrote:

> Hi all,
> 
> I maintain an as yet unreleased binutils port for an architecture that
> prepends an underscore to symbol names defined in C (for legacy
> reasons). This is normally not a problem, but some software e.g. uClibc
> wishes to reference symbols defined in the linker scripts such as
> __init_array_start, but because they are referenced in C the symbol
> referenced is actually ___init_array_start (i.e. 3 leading underscores
> rather than 2). This results in an undefined symbol at link time.
> Obviously I can hack the uClibc code to get the right symbol, but I was
> wondering if there was a better solution to this problem? Do other
> architectures have this problem e.g. sh?
> 
> Thanks,
> 
> (apologies for the excessive footer)

  Possible solutions:

1.  hack the references in the C code to remove an initial underscore
2.  hack the symbol defines in the linker script to add an initial underscore
3.  duplicate the symbol defines in the linker script with an extra underscore
but retain the original names too
4.  use some autoconf magic in uclibc so that it can know whether the C-level
symbols have an extra underscore or are the same as the asm-level symbols
according to the target, then use a macro (that either does or does not paste
an extra underscore on the front of a label name accordingly) to wrap
references in the C files to any of the assembler-level symbols that are
needed.
5.  change your custom toolchain so that it doesn't prepend underscores, or
has a command-line option to turn it on and off.

  1&2 are really fairly dirty hacks and should probably be avoided.  3 is
perfectly reasonable albeit not all that aesthetically pleasing.  4 is
probably more work than is necessary.  5 might be a good idea, if what you
want is to make a linux-based system then you could just adopt the same (no
extra underscore) convention that other linuxes use, but there may be
backward-compatibility problems with old already-compiled code objects or
shared libraries.

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Providing C level symbols via linker scripts
  2006-03-21 15:00 Providing C level symbols via linker scripts Will Newton
  2006-03-21 17:09 ` Dave Korn
@ 2006-03-21 18:50 ` Mike Frysinger
  1 sibling, 0 replies; 4+ messages in thread
From: Mike Frysinger @ 2006-03-21 18:50 UTC (permalink / raw)
  To: binutils; +Cc: Will Newton

On Tuesday 21 March 2006 09:27, Will Newton wrote:
> This is normally not a problem, but some software e.g. uClibc
> wishes to reference symbols defined in the linker scripts such as
> __init_array_start, but because they are referenced in C the symbol
> referenced is actually ___init_array_start (i.e. 3 leading underscores
> rather than 2). This results in an undefined symbol at link time.
> Obviously I can hack the uClibc code to get the right symbol, but I was
> wondering if there was a better solution to this problem?

how is this a bug in uClibc ?  the C symbol name is "__init_array_start" thus 
your architecture should be providing "___init_array_start" via binutils ... 
unless you dont handle init/fini stuff, then just disable global constructors 
support in uClibc ...

> Do other architectures have this problem e.g. sh?

blackfin is the only arch i know of that utilizes the USER_PREFIX in gcc to 
prepend an underscore ... no standard linux arch utilizes a prefix 
(alpha/amd64/arm/hppa/ia64/m68k/mips/ppc/ppc64/s390/sh/sparc/x86)
-mike

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Providing C level symbols via linker scripts
  2006-03-21 17:09 ` Dave Korn
@ 2006-03-21 20:40   ` Mike Frysinger
  0 siblings, 0 replies; 4+ messages in thread
From: Mike Frysinger @ 2006-03-21 20:40 UTC (permalink / raw)
  To: binutils; +Cc: Dave Korn, 'Will Newton'

On Tuesday 21 March 2006 10:00, Dave Korn wrote:
> 4.  use some autoconf magic in uclibc so that it can know whether the
> C-level symbols have an extra underscore or are the same as the asm-level
> symbols according to the target, then use a macro (that either does or does
> not paste an extra underscore on the front of a label name accordingly) to
> wrap references in the C files to any of the assembler-level symbols that
> are needed.

uClibc is completely make based so using autoconf is pretty much out of the 
question ... gcc exports the prefix already though via the 
__USER_LABEL_PREFIX__ define and uClibc utilizes that when generating asm 
symbol names ...
-mike

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-03-21 18:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-21 15:00 Providing C level symbols via linker scripts Will Newton
2006-03-21 17:09 ` Dave Korn
2006-03-21 20:40   ` Mike Frysinger
2006-03-21 18:50 ` Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).