[lld] 177fd72 - [ELF] Disallow input section description without a filename
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri May 13 11:06:05 PDT 2022
Author: Fangrui Song
Date: 2022-05-13T11:06:01-07:00
New Revision: 177fd72f5f223810f647d104749b40abdb9e3d6d
URL: https://github.com/llvm/llvm-project/commit/177fd72f5f223810f647d104749b40abdb9e3d6d
DIFF: https://github.com/llvm/llvm-project/commit/177fd72f5f223810f647d104749b40abdb9e3d6d.diff
LOG: [ELF] Disallow input section description without a filename
GNU ld does not allow `.foo : { (*foo) }`, but we may recognize it as three
input section descriptions: file "(" with any section name, file "*foo" with
any section name, file ")" with any section name. Disallow the error-prone usage.
Reviewed By: peter.smith
Differential Revision: https://reviews.llvm.org/D125523
Added:
Modified:
lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/no-filename-spec.s
Removed:
################################################################################
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index 51792da64b82e..e7e42aa77e0b2 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -945,6 +945,8 @@ OutputDesc *ScriptParser::readOutputSectionDescription(StringRef outSec) {
readSort();
} else if (tok == "INCLUDE") {
readInclude();
+ } else if (tok == "(" || tok == ")") {
+ setError("expected filename pattern");
} else if (peek() == "(") {
osec->commands.push_back(readInputSectionDescription(tok));
} else {
diff --git a/lld/test/ELF/linkerscript/no-filename-spec.s b/lld/test/ELF/linkerscript/no-filename-spec.s
index aec03958da7d0..5463cfd30f527 100644
--- a/lld/test/ELF/linkerscript/no-filename-spec.s
+++ b/lld/test/ELF/linkerscript/no-filename-spec.s
@@ -1,4 +1,5 @@
# REQUIRES: x86
+# RUN: rm -rf %t && split-file %s %t
# 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;' | \
@@ -6,12 +7,28 @@
## 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
+# RUN: ld.lld -o %t/a -T %t/a.t %tfile1.o %tfile2.o
+# RUN: llvm-objdump -s %t/a | FileCheck %s
# CHECK: Contents of section .foo:
# CHECK-NEXT: 01000000 00000000 02000000 00000000
+# RUN: not ld.lld -o /dev/null -T %t/b.t %tfile1.o 2>&1 | FileCheck %s --check-prefix=ERR
+# RUN: not ld.lld -o /dev/null -T %t/c.t %tfile1.o 2>&1 | FileCheck %s --check-prefix=ERR
+# RUN: not ld.lld -o /dev/null -T %t/d.t %tfile1.o 2>&1 | FileCheck %s --check-prefix=ERR
+
+# ERR: error: {{.*}}.t:1: expected filename pattern
+
+#--- a.t
SECTIONS {
.foo : { *file1.o *file2.o }
}
+
+#--- b.t
+SECTIONS { .foo : { (*foo) } }
+
+#--- c.t
+SECTIONS { .foo : { (*(foo)) } }
+
+#--- d.t
+SECTIONS { .foo : { )(*foo) } }
More information about the llvm-commits
mailing list