[PATCH] D33643: [ELF] - Allow multiple comdats when producing relocatable output.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 1 12:03:21 PDT 2017


LGTM.

Thanks,
Rafael

George Rimar via Phabricator <reviews at reviews.llvm.org> writes:

> grimar updated this revision to Diff 100669.
> grimar edited the summary of this revision.
>
> https://reviews.llvm.org/D33643
>
> Files:
>   ELF/OutputSections.cpp
>   test/ELF/Inputs/relocatable-comdat-multiple.s
>   test/ELF/relocatable-comdat-multiple.s
>
>
> Index: test/ELF/relocatable-comdat-multiple.s
> ===================================================================
> --- test/ELF/relocatable-comdat-multiple.s
> +++ test/ELF/relocatable-comdat-multiple.s
> @@ -0,0 +1,31 @@
> +# REQUIRES: x86
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/relocatable-comdat-multiple.s -o %t2.o
> +# RUN: ld.lld -r %t.o %t2.o -o %t
> +# RUN: llvm-readobj -elf-section-groups %t | FileCheck %s
> +
> +# CHECK:      Groups {
> +# CHECK-NEXT:   Group {
> +# CHECK-NEXT:     Name: .group
> +# CHECK-NEXT:     Index: 2
> +# CHECK-NEXT:     Type: COMDAT
> +# CHECK-NEXT:     Signature: aaa
> +# CHECK-NEXT:     Section(s) in group [
> +# CHECK-NEXT:       .text.a
> +# CHECK-NEXT:       .text.b
> +# CHECK-NEXT:     ]
> +# CHECK-NEXT:   }
> +# CHECK-NEXT:   Group {
> +# CHECK-NEXT:     Name: .group
> +# CHECK-NEXT:     Index: 5
> +# CHECK-NEXT:     Type: COMDAT
> +# CHECK-NEXT:     Signature: bbb
> +# CHECK-NEXT:     Section(s) in group [
> +# CHECK-NEXT:       .text.c
> +# CHECK-NEXT:       .text.d
> +# CHECK-NEXT:     ]
> +# CHECK-NEXT:   }
> +# CHECK-NEXT: }
> +
> +.section .text.a,"axG", at progbits,aaa,comdat
> +.section .text.b,"axG", at progbits,aaa,comdat
> Index: test/ELF/Inputs/relocatable-comdat-multiple.s
> ===================================================================
> --- test/ELF/Inputs/relocatable-comdat-multiple.s
> +++ test/ELF/Inputs/relocatable-comdat-multiple.s
> @@ -0,0 +1,2 @@
> +.section .text.c,"axG", at progbits,bbb,comdat
> +.section .text.d,"axG", at progbits,bbb,comdat
> Index: ELF/OutputSections.cpp
> ===================================================================
> --- ELF/OutputSections.cpp
> +++ ELF/OutputSections.cpp
> @@ -360,6 +360,15 @@
>  
>  void OutputSectionFactory::addInputSec(InputSectionBase *IS,
>                                         StringRef OutsecName) {
> +  // Used for -r. When we have multiple different SHT_GROUPs, they may have
> +  // equal names, flags and other properties. We should not combine such
> +  // sections, but create single output section for each input.
> +  if (IS->Type == SHT_GROUP) {
> +    OutputSection *Out = nullptr;
> +    addInputSec(IS, OutsecName, Out);
> +    return;
> +  }
> +
>    SectionKey Key = createKey(IS, OutsecName);
>    OutputSection *&Sec = Map[Key];
>    return addInputSec(IS, OutsecName, Sec);
>
>
> Index: test/ELF/relocatable-comdat-multiple.s
> ===================================================================
> --- test/ELF/relocatable-comdat-multiple.s
> +++ test/ELF/relocatable-comdat-multiple.s
> @@ -0,0 +1,31 @@
> +# REQUIRES: x86
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/relocatable-comdat-multiple.s -o %t2.o
> +# RUN: ld.lld -r %t.o %t2.o -o %t
> +# RUN: llvm-readobj -elf-section-groups %t | FileCheck %s
> +
> +# CHECK:      Groups {
> +# CHECK-NEXT:   Group {
> +# CHECK-NEXT:     Name: .group
> +# CHECK-NEXT:     Index: 2
> +# CHECK-NEXT:     Type: COMDAT
> +# CHECK-NEXT:     Signature: aaa
> +# CHECK-NEXT:     Section(s) in group [
> +# CHECK-NEXT:       .text.a
> +# CHECK-NEXT:       .text.b
> +# CHECK-NEXT:     ]
> +# CHECK-NEXT:   }
> +# CHECK-NEXT:   Group {
> +# CHECK-NEXT:     Name: .group
> +# CHECK-NEXT:     Index: 5
> +# CHECK-NEXT:     Type: COMDAT
> +# CHECK-NEXT:     Signature: bbb
> +# CHECK-NEXT:     Section(s) in group [
> +# CHECK-NEXT:       .text.c
> +# CHECK-NEXT:       .text.d
> +# CHECK-NEXT:     ]
> +# CHECK-NEXT:   }
> +# CHECK-NEXT: }
> +
> +.section .text.a,"axG", at progbits,aaa,comdat
> +.section .text.b,"axG", at progbits,aaa,comdat
> Index: test/ELF/Inputs/relocatable-comdat-multiple.s
> ===================================================================
> --- test/ELF/Inputs/relocatable-comdat-multiple.s
> +++ test/ELF/Inputs/relocatable-comdat-multiple.s
> @@ -0,0 +1,2 @@
> +.section .text.c,"axG", at progbits,bbb,comdat
> +.section .text.d,"axG", at progbits,bbb,comdat
> Index: ELF/OutputSections.cpp
> ===================================================================
> --- ELF/OutputSections.cpp
> +++ ELF/OutputSections.cpp
> @@ -360,6 +360,15 @@
>  
>  void OutputSectionFactory::addInputSec(InputSectionBase *IS,
>                                         StringRef OutsecName) {
> +  // Used for -r. When we have multiple different SHT_GROUPs, they may have
> +  // equal names, flags and other properties. We should not combine such
> +  // sections, but create single output section for each input.
> +  if (IS->Type == SHT_GROUP) {
> +    OutputSection *Out = nullptr;
> +    addInputSec(IS, OutsecName, Out);
> +    return;
> +  }
> +
>    SectionKey Key = createKey(IS, OutsecName);
>    OutputSection *&Sec = Map[Key];
>    return addInputSec(IS, OutsecName, Sec);


More information about the llvm-commits mailing list