This is the mail archive of the
mailing list for the binutils project.
[PATCH] BFD: Handle copying of absolute section symbols
- From: "Maciej W. Rozycki" <macro at linux-mips dot org>
- To: binutils at sourceware dot org
- Cc: Richard Sandiford <rdsandiford at googlemail dot com>
- Date: Tue, 10 Apr 2012 11:17:26 +0100 (BST)
- Subject: [PATCH] BFD: Handle copying of absolute section symbols
Some MIPS ELF files contain a special symbol called _DYNAMIC_LINKING that
is created as an absolute global section symbol; it appears as follows:
63: 0000000000000001 0 SECTION GLOBAL DEFAULT ABS _DYNAMIC_LINKING
in readelf output of .symtab or .dynsym. I'm not sure why it is arranged
as such; in particular an IRIX reference on the Internet says:
"Some symbols have a DSO-specific meaning. That is, a query of the
value within a DSO can get a DSO-specific value: the values are not
global, but specific to the main program or DSO taking the address of
the symbol. The DSO-specific symbols are: _gp, _gp_disp,
_procedure_table, _procedure_table_size, _procedure_string_table,
_rt_symbol_table, _rt_symbol_table_size, _rt_symbol_string_table,
_data_init_table, _DYNAMIC_LINK, _DYNAMIC_LINKING, and _BASE_ADDRESS.
All the other symbols are global and therefore a single value (that of
the main program) will be seen from all DSOs and the main program
because of the global symbol resolution rules."
"* _DYNAMIC_LINKING and _DYNAMIC_LINK are identical. If referred to,
they have special value generated by the linker: 0 means this code
is non-shared, 1 means the code is in a KPIC executable, and 2 means
the code is in a DSO."
so it looks to me the symbol should really be marked as local and probably
object; there's no further explanation in our sources and any input as to
why we create this symbol with such attributes will be appreciated. I
have no idea what the actual use of this symbol is either.
Anyway, this attribute arrangement causes this symbol to be always
discarded whenever a binary containing a definition is objcopied in any
way, e.g. verbatim, like with:
FAIL: simple objcopy of executable
in the binutils test suite.
I have tracked it down to ignore_section_sym in bfd/elf.c that considers
the section the symbol is associated with not to be owned by the output
BFD. Arguably the special absolute section should be treated as "owned"
by any BFD, because any symbols defined there are really detached from any
input section and the only sensible action that can be done about them
here is to copy them verbatim.
Here's a change that fixes the problem for me and the binutils test
failure quoted above. Any objections or other comments?
2012-04-10 Maciej W. Rozycki <email@example.com>
* elf.c (ignore_section_sym): Handle absolute section symbols.
@@ -3250,7 +3250,8 @@ ignore_section_sym (bfd *abfd, asymbol *
return ((sym->flags & BSF_SECTION_SYM) != 0
&& !(sym->section->owner == abfd
|| (sym->section->output_section->owner == abfd
- && sym->section->output_offset == 0)));
+ && sym->section->output_offset == 0)
+ || bfd_is_abs_section (bfd_get_section (sym))));
@@ -3294,7 +3295,8 @@ elf_map_symbols (bfd *abfd)
if ((sym->flags & BSF_SECTION_SYM) != 0
&& sym->value == 0
- && !ignore_section_sym (abfd, sym))
+ && !ignore_section_sym (abfd, sym)
+ && !bfd_is_abs_section (bfd_get_section (sym)))
asection *sec = sym->section;