From: George Rimar Date: Fri, 12 Aug 2016 19:56:57 +0000 (+0000) Subject: [ELF] - Do not use mergeable sections when LS is used. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=67e3ff83f5b438d64427c0779e8571aa745d5549;p=platform%2Fupstream%2Fllvm.git [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 llvm-svn: 278555 --- diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 7078637..55f7962 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -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::shouldMerge(const Elf_Shdr &Sec) { 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. diff --git a/lld/test/ELF/linkerscript/linkerscript-merge-sections.s b/lld/test/ELF/linkerscript/linkerscript-merge-sections.s new file mode 100644 index 0000000..bb3849a --- /dev/null +++ b/lld/test/ELF/linkerscript/linkerscript-merge-sections.s @@ -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",@progbits,1 +readable: + .long 2 + +.section .foo.3, "awx" + .long 0 + +.section .foo.4, "MS",@progbits,1 +.LASF2: + .string "short unsigned int"