[PATCH] D42190: Handle parsing AT(ADDR(.foo-bar))
Rafael Avila de Espindola via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 17 10:50:06 PST 2018
espindola created this revision.
espindola added a reviewer: ruiu.
Herald added a subscriber: emaste.
The problem we have with it is that anything inside an AT is as expression, so we fail to parse the section name because of the - in it.
https://reviews.llvm.org/D42190
Files:
ELF/ScriptParser.cpp
test/ELF/linkerscript/parse-section-in-addr.s
Index: test/ELF/linkerscript/parse-section-in-addr.s
===================================================================
--- /dev/null
+++ test/ELF/linkerscript/parse-section-in-addr.s
@@ -0,0 +1,10 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+
+# RUN: echo "SECTIONS { \
+# RUN: .foo-bar : AT(ADDR(.foo-bar)) { *(.text) } \
+# RUN: }" > %t.script
+# RUN: ld.lld -o %t.so --script %t.script %t.o -shared
+# RUN: llvm-readelf -S %t.so | FileCheck %s
+
+# CHECK: .foo-bar
Index: ELF/ScriptParser.cpp
===================================================================
--- ELF/ScriptParser.cpp
+++ ELF/ScriptParser.cpp
@@ -783,16 +783,22 @@
return make<SymbolAssignment>(Name, E, getCurrentLocation());
}
+namespace {
+// Our lexer is context-aware. This sets the in-expression bit so that
+// it applies different tokenization rules.
+struct RAIIInExpr {
+ bool Old;
+ bool *Ptr;
+ RAIIInExpr(bool *Ptr, bool Val) : Old(*Ptr), Ptr(Ptr) { *Ptr = Val; }
+ ~RAIIInExpr() { *Ptr = Old; }
+};
+} // namespace
+
// This is an operator-precedence parser to parse a linker
// script expression.
Expr ScriptParser::readExpr() {
- // Our lexer is context-aware. Set the in-expression bit so that
- // they apply different tokenization rules.
- bool Orig = InExpr;
- InExpr = true;
- Expr E = readExpr1(readPrimary(), 0);
- InExpr = Orig;
- return E;
+ RAIIInExpr R(&InExpr, true);
+ return readExpr1(readPrimary(), 0);
}
static Expr combine(StringRef Op, Expr L, Expr R) {
@@ -923,6 +929,7 @@
StringRef ScriptParser::readParenLiteral() {
expect("(");
+ RAIIInExpr R(&InExpr, false);
StringRef Tok = next();
expect(")");
return Tok;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42190.130214.patch
Type: text/x-patch
Size: 1751 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180117/a66201f7/attachment.bin>
More information about the llvm-commits
mailing list