as more-or-less definitive descriptions of how shared flat libraries
should be built and used. Please let me know if they aren't, and if
there's another recipe somewhere.
Anyway, the RFC is about two issues:
(1) Shared libraries usually have some symbols that are internally
STB_GLOBAL (because they are shared between more than one input
object) but which should nevertheless be treated as local to
the library as a whole; they shouldn't be exported to users
of the library. According to the article above, the usual
way to arrange this is to run:
objcopy -L <sym1> -L <sym2> ... foo.gdb
on the linked foo.gdb library. That certainly works, but
maintaining the list of symbols can be a bit cumbersome.
I think it would help a lot if ld-elf2flt automatically localised
symbols with hidden and internal visibility. This would allow
users to localise symbols in the library source code -- via gcc
attributes or assembly directives -- and would eliminate one
difference between shared flat libraries and shared ELF libraries.
If the library's source code hides all the appropriate symbols --
which the source code for many ELF-leaning libraries do, unless their
build system relies on something like "local:" directives in version
scripts -- then no separate -L list is needed.
(2) If a shared library and a user of a shared library both define
some symbol foo, you don't get a redefinition warning or error.
However, if the symbols are a different size, you _do_ get a warning
about that.
To me, this seems like the worst of both worlds. I can see cases
where the user would want to be told about any redefinition, and
would want a command-line option to enable that behaviour. That's
a separate issue that I'm not tackling here.
But when redefinitions are silently allowed, warning about changes
in size seems a little pointless. Shared flat libraries can't
really refer back to symbols defined by the user of the library
(such as the executable); all symbol references are resolved
when the library is statically linked. Shared flat libraries
act a lot like a restricted form of ELF -Bsymbolic libraries.
Thus having a different size of symbol S in shared library X and
user Y is very unlikely to be an issue unless the redefinition of
S is itself an issue. X is not going to refer directly to Y's
definition of S. And if you create, say, a shared C library that
includes all the C library functions needed by at least one
program on the system, it's likely that some programs will have
harmless symbol name clashes. For example, some programs might be
written with just standard C in mind, and use symbols that clash
with a POSIX, GNU or uClibc extension.
I think it would help if we weakened the exported symbols. This
would tell the linker that the symbols are only there if needed,
and that the user of the library is free to use the symbol for
something else. This wouldn't affect the redefinition diagnostic;
if that diagnostic is ever implemented, it should apply to both
global and weak symbols, because in both cases we'll have two
definitions of the same symbol.
Comments? Does this sound reasonable sane?
In case it does, the patch below implements both (1) and (2). (1) is
simple with CVS objcopy, which now has a --localize-hidden option:
Sadly, that option won't appear in an FSF release before 2.18, so I've
provided a fall-back that uses objdump and sed instead. (2) is easy
with the long-standing --weaken option.
FWIW, the patch has been tested fairly extensively on Coldfire with
shared C and C++ libraries, as well as with ad-hoc libraries. No
post-processing of these libraries was needed: you could just link with
ld-elf2flt and use the output directly.
I've tested both the --localize-hidden and fallback versions.
Richard
Signed-off-by: Richard Sandiford <richard@codesourcery.com>
David McCullough [Fri, 21 Jul 2006 13:11:04 +0000 (13:11 +0000)]
This patch adds elf2flt support for prioritised constructors and destructors,
but only when --enable-emit-relocs is in effect.
GCC puts prioritised constructors and destructors in special .ctor.N
and .dtor.N sections (where N encodes the priority). The constructors
and destructors in these sections have a lower priority than those
in the default .ctor and .dtor sections. However, we need to treat
the crtbegin.o's and crtend.o's sections specially; crtbegin.o's .[cd]tor
sections must come before all the other .[cd]tor* contents and crtend.o's
.[cd]tor sections must come after all other contents.
In --disable-emit-relocs links, it wasn't possible to treat crtbegin.o
and crtend.o specially. ld-elf2flt would do:
so all the input .[cd]tor sections would already be lumped together by the
time the script was used. This isn't a problem for --enable-emit-relocs as
it only links once.
The patch copies the [cd]tor support from the standard binutils linker
script. The question is: should the new lines be used unconditionally,
or only when --enable-emit-relocs is in effect?
We could use the new lines for --disable-emit-relocs without breaking
programs that don't use prioritised [cd]tors. However, it would be a user
interface regression for programs that _do_ use them. At the moment,
if you try to use prioritised [cd]tors with --disable-emit-relocs,
you get a linker error like this:
error: no memory region specified for loadable section `.ctors.60535'
With the new lines, the link would silently succeed, and you'd get a
runtime failure instead. I've therefore guarded the lines with
"SINGLE_LINK:", a bit like the "W_RODAT" stuff that's already there.
Tested on Coldfire, with both --enable-emit-relocs and
--disable-emit-relocs. It fixes the GCC ecos.exp tests.
Please install if OK.
Richard
Signed-off-by: Richard Sandiford <richard@codesourcery.com>
This patch adds m68k support for elf2flt -a. I've tested it with
load-to-RAM, -msep-data PIC-with-GOT and -mshared-library PIC-with-GOT.
Like ARM, but unlike V850, the new code errors out on relocs it doesn't
understand, rather than assuming that they're 32-bit fields.
It seems likely that every port that supports -a will want to print the
"reloc type not supported in this context" message; we've got two copies
already, and m68k would add a third. I've therefore moved the v850
"bad_v850_reloc_err:" code outside the #ifdef and renamed the label to
the more neutral "bad_resolved_reloc:". I've also changed the ARM code
to use this now-common code instead of its own copy.
In a similar vein, I've changed the default 32-bit field handling
so that it is the target of a new label, "good_32bit_resolved_reloc:".
The generic and v850 code can then jump to this code in their default
cases, while m68k can jump to it for R_68K_32 relocs.
The patch was written before Shaun Jackman made -p and -a work together:
I'd been using this hunk too, but as well as guarding:
q->address += got_size;
with "!use_resolved", I'd guarded the calculation of got_size itself,
as the value isn't otherwise used. I've kept this additional check
in the attached patch. Please apply if OK.
Signed-off-by: Richard Sandiford <richard@codesourcery.com>
David McCullough [Mon, 19 Jun 2006 22:00:41 +0000 (22:00 +0000)]
We've eliminated the use of the relocation stack from the Blackfin
toolchain. That means that the corresponding code in elf2flt can go
away, which is done by the patch below.
Greg Ungerer [Thu, 15 Jun 2006 01:48:46 +0000 (01:48 +0000)]
Newly autoconf generated configure script. It was out-of-date relative
to the current configure.in. It didn't properly process
@binutils_ldscript_dir@, and that meant it was not properly set
in the ld-elf2flt.in/elf2flt.ld processing.
David McCullough [Tue, 23 May 2006 22:28:31 +0000 (22:28 +0000)]
The patch below teaches elf2flt to handle R_68K_PC16 relocs.
Our immediate need for this was to deal with relocs for uClibc's
libc/sysdeps/linux/m68k/clone.S, which has "bcc.w __syscall_error"
instructions. It might be argued that clone.S should be using jbcc
instead, in case __syscall_error ends up too far away. But even if
that's true, elf2flt should still support such branches in cases
whether the user _knows_ that the target is within range.
So I think elf2flt should be patched either way.
We've been using this patch for a while now without problems.
Please install if OK.
Richard
Signed-off-by: Richard Sandiford <richard@codesourcery.com>
Changed the mode argument for all the popen() calls to be just "w",
instead of "wb". According to the Linux manual page posix implementations
must accept only "r" or "w", no other characters. And you will get a
return error with EINVAL with modern version og glibc if this is not
the case.
It may well be that this is fine for CYGWIN too, someone needs to
test and report.
Calls to fopen and the like are unchanged, and they certainly do
support the "b" mode specifier.
For some (unfathomable) reason, the flat loader in the kernel likes to
use network (big endian) byte order, but only sometimes. In particular,
its assumptions about relocation byte order depend on whether the
executable uses ID shared libraries or not.
It took me most of today to figure out why the kernel was trying to
relocate something at address 0x94160000, until I noticed that that's
the byteswapped version of 0x1694, and further noticed that it was
omitting a byteswap due to the flag Has-PIC-GOT in the flat header.
So, why is that flag set? After all, opreport wasn't compiled with
-mid-shared-library or anything.
It turns out that elf2flt sets that flag if grepping the executable for
GLOBAL_OFFSET_TABLE succeeds. That's a reasonable thing to do, except
when we link an executable against libbfd.a - which contains
GLOBAL_OFFSET_TABLE not as a symbol, but as a string, as it needs to
produce the symbol in linker output files.
Changing elf2flt to grep nm output, rather than the executable directly,
fixes the problem. So, in the end it turns out this wasn't related to
the 20030928 failure at all...
David McCullough [Thu, 23 Mar 2006 23:06:49 +0000 (23:06 +0000)]
This patch adds support for .preinit_array, .init_array and .fini_array
to the elf2flt linker script. This seems useful in itself, and is
actually required for recent versions of uclibc, where UCLIBC_CTOR_DTOR=y
depends on the associated array symbols being defined.
Tested on m68k-uclinux using the gcc and g++ DejaGNU testsuites. I also
ran some tests by hand to make sure that callbacks in the array sections
were being called at the right time. Please install if OK.
Richard
Signed-off-by: Richard Sandiford <richard@codesourcery.com>
David McCullough [Wed, 22 Feb 2006 01:29:27 +0000 (01:29 +0000)]
Hello,
the following trivial patch is required to build elf2flt
on Darwin. Weirdly, static compilation is intentionally
unsupported by Apple for better compatibility:
http://developer.apple.com/qa/qa2001/qa1118.html
As elf2flt binaries are usually shipped along with other
dynamic binaries such as gcc and gdb, we don't loose
anything on Linux.
I'd commit it myself, but I can't access the CVS server
right now.
This patch allows cross-compilation of elf2flt for MinGW hosts when a
non-MinGW build system is in use. By using uname, there is currently an
assumption in 'Makefile.in' that (build system) == (host system), which
isn't necessarily the case in a Canadian cross environment. (At
CodeSourcery we use Linux for building our MinGW-hosted toolchains, some
of which will soon include elf2flt).
Greg Ungerer [Fri, 13 Jan 2006 06:08:01 +0000 (06:08 +0000)]
seems my previous attempt at updating the current elf2flt code with nios
relocations was slightly wrong ... the code needs to be moved down a few
hundred lines :)
Patch submitted by Mike Frysinger <vapier@gentoo.org>
David McCullough [Wed, 28 Sep 2005 05:26:02 +0000 (05:26 +0000)]
Hi,
I'm the maintainer of a windows hosted arm-elf gcc toolchain used mostly
for homebrew console development. One of my users recently asked if I
could have a look a getting elf2flt to build under mingw/msys to help
with his uclinux Nintendo DS port. I've attached a patch containing the
changes I made to the source in CVS, thought it might be useful.
2005-09-25 Dave Murphy <davem@devkitpro.org>
* Makefile.in: add ws2_32 library when building from msys shell.
* cygwin-elf.h: On mingw.include stdint.h and add extra typedefs
* elf2flt.c: Include cygwin-elf.h on mingw too.
* flthdr.c: For mingw use winsock2.h for internet consts & structs ,
use mktemp instead of mkstemp
John Williams [Tue, 3 May 2005 23:26:11 +0000 (23:26 +0000)]
Tweaked Makefile.in so that post-configured Makefile tests for a Cygwin build
environment, and if detected, explicitly adjusts the link order so that
libcygwin links *before* libiberty.a. This gets around a Cygwin problem with
getopt()'s optind/optarg symbols. See, for example:
David McCullough [Fri, 19 Mar 2004 00:17:18 +0000 (00:17 +0000)]
A small patch to ld-elf2flt.in, that lets an elf2flt-ified toolchain run
from a directory other than that specifed in the original ./configure.
Helpful if you distribute toolchains and can't control where people
install them! :) Also helpful if you are testing toolchains and need to
move them around after the elf2flt "make install".
In order to use m68k-uclinux globally as the new toolchain target,
I had to replace config.sub and config.guess in elf2flt with updated
versions already containing the required bits.
Greg Ungerer [Tue, 11 Nov 2003 07:23:04 +0000 (07:23 +0000)]
Find attached the patch for the elf2flt utility. Except the elf2flt.c file, I have slightly modified the Makefile.in. The reason for this is to check the target architecture and if it is set to "e1", another linker script is installed. The reason for this alchemy is that our linker needs some sections that are included in the e1-elf2flt.ld script.
Patch submitted by Yannis Mitsos <gmitsos@telecom.ntua.gr>.
David McCullough [Sun, 17 Aug 2003 23:41:40 +0000 (23:41 +0000)]
I've found the bug! A BSS link-once section was missing in elf2flt.ld.
The old version of GCC probably didn't ever generate this kind of
section because it was placing everything in the data link-once section.
Patch from Bernardo Innocenti <bernie@develer.com>
this patch adds Cygwin support to elf2flt. Also include a copy
of the elf.h header which is missing on Win32.
This is just a cleaned-up version of Leon's former Cygwin patch
and I couldn't really test it on Windows. At least I can ensure
it doesn't break anything on Linux :-)
David McCullough [Tue, 29 Jul 2003 10:47:48 +0000 (10:47 +0000)]
Fixed handling of MICROBLAZE_32 reloc type. The mb-gcc distributes
relocations across several places - the "standard" ones such as
q->addend and bfd_section_vma(), but also embeds small offsets in the
actual text (code) itself. Thus, it is necessary to examine the text to
get an initial offset, then add that to the others to get the final
fixup location.
This is required for at least MICROBLAZE_64 and MICROBLAZE_32 - others
may also need it.
Patch from John Williams <jwilliams@itee.uq.edu.au>
1.) Previously it was writing the relocated pointer at the pointer's section
offset from the start of the containing _segment_, not the start of the
containing section (it doesn't affect most people because for normal
usage, they're the same).
David McCullough [Fri, 30 May 2003 07:02:26 +0000 (07:02 +0000)]
Fix the zero padding so that it doesn't crash if tehre is more than 1K of
padding required.
Fix the shared library support which, although the library is at a high
address, we don't want to pad the file to +16Mb. We also do not want the
relocations starting +16Mb into the file :-)
Greg Ungerer [Thu, 22 May 2003 07:10:54 +0000 (07:10 +0000)]
Multiple sections of a given type are combined, and any holes between
sections are filled with zeroes.
This changes the definition of `text', `data', and `bss' to use the
flags set by BFD, rather than requiring hardwired input section names
(for the normal case where one is using GNU ld and the elf2flt.ld linker
script, this should produce identical results, as that only ever
produces the three well-defined sections anyway).
Greg Ungerer [Thu, 22 May 2003 05:42:19 +0000 (05:42 +0000)]
Added support for the Microblaze archiecture.
The only mod outside the #ifdef TARGET_microblaze stuff in elf2flt.c is a new
entry in config.sub so it knows about the target, and a new entry in the
elf2flt.ld because the microblaze gnu tools create sections called (.bss.*).
Patch from John Williams <jwilliams@itee.uq.edu.au>.
David McCullough [Wed, 16 Apr 2003 06:16:00 +0000 (06:16 +0000)]
Added a --disable-got-check for platforms that can't do PIC/GOT yet, and
more so for h8300 binutils that cannot do the double link stage normally
used by ld-elf2flt.
David McCullough [Fri, 14 Mar 2003 04:26:42 +0000 (04:26 +0000)]
arm expects the data segment on a 32 byte boundary, otherwise the GOT
entries can throw the alignment of the relocations out and things get
pretty ugly from there.
Changes needed to fix arm-elf debugging and pthreads on ARM and m68k
It also fixes random crashes on ARM where the end of data was not
aligned on a 16byte boundary.
Erik Andersen [Wed, 31 Jul 2002 09:07:41 +0000 (09:07 +0000)]
gcc 3.1 and 3.1.1 create a .jcr ELF section, which apparently is intended to
contain a list of pointers to classes to be registered during constructor
invoction time. Sigh. So make elf2flt work with newer gcc versions.
-Erik
David McCullough [Mon, 18 Feb 2002 04:58:36 +0000 (04:58 +0000)]
Added -with-bfd-include-dir=<dir> option as we have to use the bfd.h
that matches the libbfd.a we are using, otherwise, elf2flt may coredump if
the system header is incompatible with the libbfd.a used.