{GOLD][PATCH PROPOSAL] prevent discarding of needed local symbols for the relocatable objects

Ian Lance Taylor iant@google.com
Thu Feb 11 02:14:00 GMT 2010


Viktor Kutuzov <vkutuzov@accesssoftek.com> writes:

> I'm trying to cross build llvm and llvm-gcc on Linux for ARM by using
> GOLD as the linker. This has exposed some problems we have in GOLD. 
>
> One of them related to the assert in the relocate_for_relocatable()
> method (target-reloc.h, line 557):
>
>   new_symndx = object->symtab_index(r_sym);
>   gold_assert(new_symndx != -1U);
>
> This assert gets triggered when the build links glibc with the -r -X
> flags (remove local symbols).
>
> This happens because with the given -X option GOLD removes all local
> symbols, including those which still needed to resolve static relocs
> later.
>
> LD keeps that kind of local symbols in the symbol table even if -X
> requested. I guess GOLD should do the same.
>
> Please find attached the patch that fixes this issue.

Thanks, but this patch doesn't work.  It fails the testsuite.  The
problem is that at the time your patch checks
needs_output_symtab_entry, it will always return true.
needs_output_symtab_entry will only return false if
set_no_output_symtab_entry has been called, and that only happens at
the end of the loop you patched.

I think what we need to do here is mark the local symbol as
appropriate in scan_relocatable_relocs.  The use of the
output_symtab_index_ field right now is a bit complicated.  It is
initialized to 0.  In Sized_relobj::do_count_local_symbols we set the
field to -1 if the symbol is not needed.  In
Sized_relobj::do_finalize_local_symbols, if the field is still 0, we
set it to the index in the output file.  Perhaps we should change that
0 == uninitialized, -1 == no index, -2 == needs index.  Then
do_finalize_local_symbols should never see 0.

Ian



More information about the Binutils mailing list