This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] Gold: Implement the '--discard-locals' and '-X' options.
- From: Ian Lance Taylor <iant at google dot com>
- To: Doug Kwan (éæå) <dougkwan at google dot com>
- Cc: binutils at sourceware dot org
- Date: Fri, 05 Jun 2009 08:52:11 -0700
- Subject: Re: [PATCH] Gold: Implement the '--discard-locals' and '-X' options.
- References: <498552560906041857s6c99f14dw53ab31d703628a8b@mail.gmail.com>
"Doug Kwan (éæå)" <dougkwan@google.com> writes:
> const char* name = pnames + sym.get_st_name();
> + if (discard_locals
> + && sym.get_st_type() != elfcpp::STT_FILE
> + && parameters->target().is_local_label_name(name))
> + {
> + lv.set_no_output_symtab_entry();
> + gold_assert(!lv.needs_output_dynsym_entry());
> + continue;
> + }
Instead of asserting, don't discard the symbol if
lv.needs_output_dynsym_entry() returns true.
> + // Virtual function which may be overriden by the child class.
> + virtual bool
> + do_is_local_label_name(const char* name) const
> + {
> + // The logic is the same as that in _bfd_elf_is_local_label_name().
> +
> + // Normal local symbols start with ``.L''.
> + if (name[0] == '.' && name[1] == 'L')
> + return true;
> +
> + // At least some SVR4 compilers (e.g., UnixWare 2.1 cc) generate
> + // DWARF debugging symbols starting with ``..''.
> + if (name[0] == '.' && name[1] == '.')
> + return true;
> +
> + // gcc will sometimes generate symbols beginning with ``_.L_'' when
> + // emitting DWARF debugging output. I suspect this is actually a
> + // small bug in gcc (it calls ASM_OUTPUT_LABEL when it should call
> + // ASM_GENERATE_INTERNAL_LABEL, and this causes the leading
> + // underscore to be emitted on some ELF targets). For ease of use,
> + // we treat such symbols as local.
> + if (name[0] == '_' && name[1] == '.' && name[2] == 'L' && name[3] == '_')
> + return true;
> +
> + return false;
> + }
This is too big to define inline in the class. Define it in target.h
just below the class definition. Add a target.cc file and define it
there.
> +# '-Wa,--keep-locals' is required to preserve the local label used for testing.
> +discard_locals_test.o: discard_locals_test.c
> + $(COMPILE) -c -Wa,--keep-locals -o $@ $<
s/--keep-locals/-L/g
> +int
> +main (void)
> +{
> + /* local symbol format for generic ELF target. */
> + asm (".Lshould_be_discarded:");
> +
> +#ifdef __i386__
> + /* additional local symbol format for the i386 target. */
> + asm (".Xshould_be_discarded:");
> +#endif
> +
> + return 0;
> +}
I think it would be better to put the asm statements outside of the main
function.
Please send another patch with these changes for final approval.
Thanks.
Ian