This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Providing C level symbols via linker scripts


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....


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]