[lld] r278555 - [ELF] - Do not use mergeable sections when LS is used.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 26 00:57:42 PDT 2016


These sections are:

[ 6] .rodata           PROGBITS         ffffffff80c87c8c  00c86c8c
     00000000000e6e4d  0000000000000001 AMS       0     0     1
[ 7] .rodata           PROGBITS         ffffffff80d6eae0  00d6dae0
     0000000000246f00  0000000000000000   A       0     0     32
[ 8] .rodata           PROGBITS         ffffffff80fb59e0  00fb49e0
     00000000000001f0  0000000000000010  AM       0     0     16
[ 9] .rodata           PROGBITS         ffffffff80fb5bd0  00fb4bd0
     00000000000002a0  0000000000000004 AMS       0     0     16
[10] .rodata           PROGBITS         ffffffff80fb5e70  00fb4e70
     0000000000000108  0000000000000008  AM       0     0     8
[11] .rodata           PROGBITS         ffffffff80fb5f78  00fb4f78
     000000000000000c  0000000000000004 AMS       0     0     4
[12] .rodata           PROGBITS         ffffffff80fb5f88  00fb4f88
     0000000000001158  0000000000000001 AMS       0     0     8

> * Still creating multiple sections if one in SHF_MERGE and another is not.
Problem of this solution is that it is confusing. For example script has
SIZEOF command which should return the size of output section.
It is not clear how it should work then. Also imagine something like:

.rodata 0x12345 : { *(.rodata) }

This way we can't create 2 sections at the same VA. I can imaging
other confusing examples.
Currently we create one output section from single description and
that makes logic to be pretty understandable. I would try not to break it 
until other acceptable solutions are possible.

> * Allow adding a merge input section to a regular output section. That
way at least we disable the merging only if mismatched flags are found
and only for that section.

This probably can work. I`ll try to implement the patch for that.

Best regards,
George.
________________________________________
От: Rafael Espíndola <rafael.espindola at gmail.com>
Отправлено: 25 августа 2016 г. 21:10
Кому: George Rimar
Копия: llvm-commits
Тема: Re: [lld] r278555 - [ELF] - Do not use mergeable sections when LS is used.

This is pretty brutal.

What are the sections in the kernel that are sometimes SHF_MERGE and
sometimes are not?

I would suggest trying

* Still creating multiple sections if one in SHF_MERGE and another is not.
* Allow adding a merge input section to a regular output section. That
way at least we disable the merging only if mismatched flags are found
and only for that section.

Cheers,
Rafael





On 12 August 2016 at 15:56, George Rimar via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: grimar
> Date: Fri Aug 12 14:56:57 2016
> New Revision: 278555
>
> URL: http://llvm.org/viewvc/llvm-project?rev=278555&view=rev
> Log:
> [ELF] - Do not use mergeable sections when LS is used.
>
> After latest changes we combine input sections with
> different attributes into single output section.
> Problem here is that regular output sections does not
> support adding mergeable input sections (and vise versa).
> Patch just temporarily disables merging for now at
> the same way we do for -O0 for example.
>
> This change helps for linking FreeBSD kernel.
>
> Differential revision: https://reviews.llvm.org/D23447
>
> Added:
>     lld/trunk/test/ELF/linkerscript/linkerscript-merge-sections.s
> Modified:
>     lld/trunk/ELF/InputFiles.cpp
>
> Modified: lld/trunk/ELF/InputFiles.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=278555&r1=278554&r2=278555&view=diff
> ==============================================================================
> --- lld/trunk/ELF/InputFiles.cpp (original)
> +++ lld/trunk/ELF/InputFiles.cpp Fri Aug 12 14:56:57 2016
> @@ -11,6 +11,7 @@
>  #include "Driver.h"
>  #include "Error.h"
>  #include "InputSection.h"
> +#include "LinkerScript.h"
>  #include "SymbolTable.h"
>  #include "Symbols.h"
>  #include "llvm/ADT/STLExtras.h"
> @@ -162,6 +163,14 @@ bool elf::ObjectFile<ELFT>::shouldMerge(
>    if (Config->Optimize == 0)
>      return false;
>
> +  // We don't merge if linker script has SECTIONS command. When script
> +  // do layout it can merge several sections with different attributes
> +  // into single output sections. We currently do not support adding
> +  // mergeable input sections to regular output ones as well as adding
> +  // regular input sections to mergeable output.
> +  if (ScriptConfig->HasContents)
> +    return false;
> +
>    // A mergeable section with size 0 is useless because they don't have
>    // any data to merge. A mergeable string section with size 0 can be
>    // argued as invalid because it doesn't end with a null character.
>
> Added: lld/trunk/test/ELF/linkerscript/linkerscript-merge-sections.s
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/linkerscript-merge-sections.s?rev=278555&view=auto
> ==============================================================================
> --- lld/trunk/test/ELF/linkerscript/linkerscript-merge-sections.s (added)
> +++ lld/trunk/test/ELF/linkerscript/linkerscript-merge-sections.s Fri Aug 12 14:56:57 2016
> @@ -0,0 +1,28 @@
> +# REQUIRES: x86
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
> +
> +# RUN: echo "SECTIONS { .foo : { *(.foo.*) } }" > %t.script
> +# RUN: ld.lld -o %t1 --script %t.script %t
> +# RUN: llvm-objdump -s %t1 | FileCheck %s
> +# CHECK:      Contents of section .foo:
> +# CHECK-NEXT:  0158 01000000 02000000 00000000 73686f72  ............shor
> +# CHECK-NEXT:  0168 7420756e 7369676e 65642069 6e7400    t unsigned int.
> +
> +.global _start
> +_start:
> +  nop
> +
> +.section .foo.1, "aw"
> +writable:
> + .long 1
> +
> +.section .foo.2, "aM", at progbits,1
> +readable:
> + .long 2
> +
> +.section .foo.3, "awx"
> + .long 0
> +
> +.section .foo.4, "MS", at progbits,1
> +.LASF2:
> + .string "short unsigned int"
>
>
> _______________________________________________
> 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