[PATCH] D40950: [ELF] - Fail when multiple .debug_* sections are used in a single object.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 09:44:31 PST 2017


What's the error handling case you mention? Presumably it works for
multiple debug_types sections, so perhaps that support could be generalized
to multiple debug_info sections as well? Then this failure could be
restricted to only multiple debug_info sections when using gdb-index?

That way DWARF5 type units (that use debug_info sections) would just work?
(except when using gdb-index)

It seems strange to me that the linker would special case the debug_*
sections (& that that special casing would limit how they can be used)
given the discussion we were having about the linker wanting to treat debug
info as just normal sections.

On Thu, Dec 7, 2017 at 4:39 AM George Rimar via Phabricator <
reviews at reviews.llvm.org> wrote:

> grimar created this revision.
> Herald added subscribers: JDevlieghere, aprantl, emaste.
>
> It is based on discussions in "[llvm-dev] [RFC] - Deduplication of debug
> information in linkers (LLD)." thread.
> DWARF5 specification (http://dwarfstd.org/doc/DWARF5.pdf) mentions it can
> be one or more of debug sections.
> For example:
>
> 1. p366 says objects may have multiple .debug_abrev, .debug_info,
> .debug_line sections for DWARF elimination.
> 2. p376 says multiple .debug_info section could be used for deduplication
> of type units.
>
> In both cases LLD would work incorrectly now (as we do not expect multiple
> of above sections) for cases when we are
> trying to work with DWARF sections. It is error reporting case and
> --gdb-index generation case.
> So for both safety and simplicity of implementation I suggest to error out
> when LLDDwarfObj meets object with
> any multiple debug sections with the same name.
>
>
> https://reviews.llvm.org/D40950
>
> Files:
>   ELF/GdbIndex.cpp
>   ELF/GdbIndex.h
>   test/ELF/multiple-debug-sections.s
>
>
> Index: test/ELF/multiple-debug-sections.s
> ===================================================================
> --- test/ELF/multiple-debug-sections.s
> +++ test/ELF/multiple-debug-sections.s
> @@ -0,0 +1,24 @@
> +# REQUIRES: x86
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o
> +# RUN: not ld.lld --gdb-index %t1.o -o %t 2>&1 | FileCheck %s
> +# CHECK: error: {{.*}}.o: multiple .debug_info sections are not supported
> +# CHECK: error: {{.*}}.o: multiple .debug_abbrev sections are not
> supported
> +# CHECK: error: {{.*}}.o: multiple .debug_line sections are not supported
> +
> +.section  .debug_info,"", at progbits
> +.quad 0
> +
> +.section  .debug_info,"G", at progbits,foo,comdat
> +.quad 0
> +
> +.section  .debug_abbrev,"", at progbits
> +.quad 0
> +
> +.section  .debug_abbrev,"G", at progbits,foo,comdat
> +.quad 0
> +
> +.section  .debug_line,"", at progbits
> +.quad 0
> +
> +.section  .debug_line,"G", at progbits,foo,comdat
> +.quad 0
> Index: ELF/GdbIndex.h
> ===================================================================
> --- ELF/GdbIndex.h
> +++ ELF/GdbIndex.h
> @@ -36,6 +36,8 @@
>    llvm::Optional<llvm::RelocAddrEntry> findAux(const InputSectionBase
> &Sec,
>                                                 uint64_t Pos,
>                                                 ArrayRef<RelTy> Rels)
> const;
> +  // Used to detect multiple debug sections with the same name.
> +  llvm::StringSet<> Seen;
>
>  public:
>    explicit LLDDwarfObj(ObjFile<ELFT> *Obj);
> Index: ELF/GdbIndex.cpp
> ===================================================================
> --- ELF/GdbIndex.cpp
> +++ ELF/GdbIndex.cpp
> @@ -26,8 +26,13 @@
>
>  template <class ELFT> LLDDwarfObj<ELFT>::LLDDwarfObj(ObjFile<ELFT> *Obj) {
>    for (InputSectionBase *Sec : Obj->getSections()) {
> -    if (!Sec)
> +    if (!Sec || !Sec->Name.startswith(".debug"))
>        continue;
> +
> +    if (!Seen.insert(Sec->Name).second)
> +      error(toString(Obj) + ": multiple " + Sec->Name +
> +            " sections are not supported");
> +
>      if (LLDDWARFSection *M = StringSwitch<LLDDWARFSection *>(Sec->Name)
>                                   .Case(".debug_info", &InfoSection)
>                                   .Case(".debug_ranges", &RangeSection)
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171207/34a72bda/attachment.html>


More information about the llvm-commits mailing list