[lld] r348463 - [LLD][ELF] - Linker script: accept using a file name without a list of sections.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 6 00:34:52 PST 2018


Author: grimar
Date: Thu Dec  6 00:34:52 2018
New Revision: 348463

URL: http://llvm.org/viewvc/llvm-project?rev=348463&view=rev
Log:
[LLD][ELF] - Linker script: accept using a file name without a list of sections.

This is a part of
https://bugs.llvm.org/show_bug.cgi?id=39885

Linker script specification says:
"You can specify a file name to include sections from a particular file. You would
do this if one or more of your files contain special data that needs to be at a
particular location in memory."

LLD did not accept this syntax. The patch implements it.

Differential revision: https://reviews.llvm.org/D55324

Added:
    lld/trunk/test/ELF/linkerscript/no-filename-spec.s
Modified:
    lld/trunk/ELF/LinkerScript.h
    lld/trunk/ELF/ScriptParser.cpp
    lld/trunk/test/ELF/linkerscript/sort.s

Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=348463&r1=348462&r2=348463&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Thu Dec  6 00:34:52 2018
@@ -146,7 +146,9 @@ struct MemoryRegion {
 // Also it may be surrounded with SORT() command, so contains sorting rules.
 struct SectionPattern {
   SectionPattern(StringMatcher &&Pat1, StringMatcher &&Pat2)
-      : ExcludedFilePat(Pat1), SectionPat(Pat2) {}
+      : ExcludedFilePat(Pat1), SectionPat(Pat2),
+        SortOuter(SortSectionPolicy::Default),
+        SortInner(SortSectionPolicy::Default) {}
 
   StringMatcher ExcludedFilePat;
   StringMatcher SectionPat;

Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=348463&r1=348462&r2=348463&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Thu Dec  6 00:34:52 2018
@@ -854,7 +854,12 @@ OutputSection *ScriptParser::readOutputS
     } else if (peek() == "(") {
       Cmd->SectionCommands.push_back(readInputSectionDescription(Tok));
     } else {
-      setError("unknown command " + Tok);
+      // We have a file name and no input sections description. It is not a
+      // commonly used syntax, but still acceptable. In that case, all sections
+      // from the file will be included.
+      InputSectionDescription *ISD = make<InputSectionDescription>(Tok);
+      ISD->SectionPatterns.push_back({{}, StringMatcher({"*"})});
+      Cmd->SectionCommands.push_back(ISD);
     }
   }
 

Added: lld/trunk/test/ELF/linkerscript/no-filename-spec.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/no-filename-spec.s?rev=348463&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/no-filename-spec.s (added)
+++ lld/trunk/test/ELF/linkerscript/no-filename-spec.s Thu Dec  6 00:34:52 2018
@@ -0,0 +1,17 @@
+# REQUIRES: x86
+# RUN: echo '.section .bar, "a"; .quad 1;' | \
+# RUN:   llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %tfile1.o
+# RUN: echo '.section .zed, "a"; .quad 2;' | \
+# RUN:   llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %tfile2.o
+
+## We have a file name and no input sections description. In that case, all
+## sections from the file specified should be included. Check that.
+# RUN: ld.lld -o %t --script %s %tfile1.o %tfile2.o
+# RUN: llvm-objdump -s %t | FileCheck %s
+
+# CHECK:      Contents of section .foo:
+# CHECK-NEXT:  01000000 00000000 02000000 00000000
+
+SECTIONS {
+ .foo : { *file1.o *file2.o }
+}

Modified: lld/trunk/test/ELF/linkerscript/sort.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/sort.s?rev=348463&r1=348462&r2=348463&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/sort.s (original)
+++ lld/trunk/test/ELF/linkerscript/sort.s Thu Dec  6 00:34:52 2018
@@ -95,11 +95,6 @@
 # RUN: ld.lld -o %t11 --script %t10.script %t2.o %t1.o
 # RUN: llvm-objdump -s %t11 | FileCheck -check-prefix=SORTED_A %s
 
-## There is no SORTFOO command, check we handle it properly.
-# RUN: echo "SECTIONS { .aaa : { SORTFOO } }" > %t3.script
-# RUN: not ld.lld -o %t3 --script %t3.script %t1.o 2>&1 | FileCheck %s -check-prefix=SORTFOO
-# SORTFOO: unknown command SORTFOO
-
 .global _start
 _start:
  nop




More information about the llvm-commits mailing list