[PATCH] D43942: [lld] Fix handling of output section selection for unmerged mergeable inputs and relocatable output

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 1 08:48:28 PST 2018


What is the problem with having multiple sections with the same name?

Cheers,
Rafael

Owen Reynolds via Phabricator via llvm-commits
<llvm-commits at lists.llvm.org> writes:

> gbreynoo created this revision.
> gbreynoo added reviewers: grimar, ruiu.
> Herald added subscribers: llvm-commits, arichardson, emaste.
>
> Usually mergeable sections, those with the flag SHF_MERGE, can be combined into synthetic sections; however use of the optimisation flag "-O0" does not allow this merging. When "-O0" is called with relocatable object output "-r", these non synthetic sections are used to create output sections. This allows the incorrect output of multiple sections with same name.
>
> The change below ensures only synthetic sections are used to create output sections in this way.
>
>
> Repository:
>   rLLD LLVM Linker
>
> https://reviews.llvm.org/D43942
>
> Files:
>   ELF/LinkerScript.cpp
>   test/ELF/merge-relocatable-O0.s
>
>
> Index: test/ELF/merge-relocatable-O0.s
> ===================================================================
> --- test/ELF/merge-relocatable-O0.s
> +++ test/ELF/merge-relocatable-O0.s
> @@ -0,0 +1,17 @@
> +# 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 -o %t2.o
> +# RUN: ld.lld -r -O0 %t.o %t2.o -o %t
> +# RUN: llvm-objdump -section-headers %t | FileCheck %s --check-prefix=RODATA
> +# RUN: llvm-objdump -section-headers %t | FileCheck %s --check-prefix=DEBUG_STR
> +
> +# RODATA:         .rodata.1
> +# RODATA-NOT:     .rodata.1
> +# DEBUG_STR:         .debug_str
> +# DEBUG_STR-NOT:     .debug_str
> +
> +.section        .rodata.1,"aM", at progbits,4
> +        .align  4
> +        .long   0x42
> +.section         .debug_str,"MS", at progbits,1
> +        .asciz  "string"
> Index: ELF/LinkerScript.cpp
> ===================================================================
> --- ELF/LinkerScript.cpp
> +++ ELF/LinkerScript.cpp
> @@ -498,7 +498,8 @@
>    // When control reaches here, mergeable sections have already been merged into
>    // synthetic sections. For relocatable case we want to create one output
>    // section per syntetic section so that they have a valid sh_entsize.
> -  if (Config->Relocatable && (IS->Flags & SHF_MERGE))
> +  if (Config->Relocatable && (IS->Flags & SHF_MERGE) &&
> +    isa<SyntheticSection> (IS))
>      return createSection(IS, OutsecName);
>  
>    //  The ELF spec just says
>
>
> Index: test/ELF/merge-relocatable-O0.s
> ===================================================================
> --- test/ELF/merge-relocatable-O0.s
> +++ test/ELF/merge-relocatable-O0.s
> @@ -0,0 +1,17 @@
> +# 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 -o %t2.o
> +# RUN: ld.lld -r -O0 %t.o %t2.o -o %t
> +# RUN: llvm-objdump -section-headers %t | FileCheck %s --check-prefix=RODATA
> +# RUN: llvm-objdump -section-headers %t | FileCheck %s --check-prefix=DEBUG_STR
> +
> +# RODATA:         .rodata.1
> +# RODATA-NOT:     .rodata.1
> +# DEBUG_STR:         .debug_str
> +# DEBUG_STR-NOT:     .debug_str
> +
> +.section        .rodata.1,"aM", at progbits,4
> +        .align  4
> +        .long   0x42
> +.section         .debug_str,"MS", at progbits,1
> +        .asciz  "string"
> Index: ELF/LinkerScript.cpp
> ===================================================================
> --- ELF/LinkerScript.cpp
> +++ ELF/LinkerScript.cpp
> @@ -498,7 +498,8 @@
>    // When control reaches here, mergeable sections have already been merged into
>    // synthetic sections. For relocatable case we want to create one output
>    // section per syntetic section so that they have a valid sh_entsize.
> -  if (Config->Relocatable && (IS->Flags & SHF_MERGE))
> +  if (Config->Relocatable && (IS->Flags & SHF_MERGE) &&
> +    isa<SyntheticSection> (IS))
>      return createSection(IS, OutsecName);
>  
>    //  The ELF spec just says
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list