<div dir="ltr">Isn't this almost the same as the Eugene's patch?<div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 31, 2016 at 10:43 AM, Rafael Espindola via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Mon Oct 31 12:43:38 2016<br>
New Revision: 285608<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=285608&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=285608&view=rev</a><br>
Log:<br>
Move IsAbsolute from SymbolAssignment to Expr.<br>
<br>
And as a token of the new feature, make ALIGNOF always absolute.<br>
<br>
This is a step in making it possible to have non absolute symbols out<br>
of output sections.<br>
<br>
Added:<br>
lld/trunk/test/ELF/<wbr>linkerscript/absolute-expr.s<br>
Modified:<br>
lld/trunk/ELF/LinkerScript.cpp<br>
lld/trunk/ELF/LinkerScript.h<br>
<br>
Modified: lld/trunk/ELF/LinkerScript.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=285608&r1=285607&r2=285608&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>LinkerScript.cpp?rev=285608&<wbr>r1=285607&r2=285608&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/LinkerScript.cpp (original)<br>
+++ lld/trunk/ELF/LinkerScript.cpp Mon Oct 31 12:43:38 2016<br>
@@ -64,7 +64,7 @@ template <class ELFT> static void addSyn<br>
}<br>
<br>
template <class ELFT> static void addSymbol(SymbolAssignment *Cmd) {<br>
- if (Cmd->IsAbsolute)<br>
+ if (Cmd->Expression.IsAbsolute)<br>
addRegular<ELFT>(Cmd);<br>
else<br>
addSynthetic<ELFT>(Cmd);<br>
@@ -1424,7 +1424,7 @@ SymbolAssignment *ScriptParser::readProv<br>
Cmd = readProvideHidden(true, true);<br>
}<br>
if (Cmd && MakeAbsolute)<br>
- Cmd->IsAbsolute = true;<br>
+ Cmd->Expression.IsAbsolute = true;<br>
return Cmd;<br>
}<br>
<br>
@@ -1436,20 +1436,19 @@ static uint64_t getSymbolValue(StringRef<br>
<br>
SymbolAssignment *ScriptParser::readAssignment(<wbr>StringRef Name) {<br>
StringRef Op = next();<br>
- bool IsAbsolute = false;<br>
Expr E;<br>
assert(Op == "=" || Op == "+=");<br>
if (consume("ABSOLUTE")) {<br>
// The RHS may be something like "ABSOLUTE(.) & 0xff".<br>
// Call readExpr1 to read the whole expression.<br>
E = readExpr1(readParenExpr(), 0);<br>
- IsAbsolute = true;<br>
+ E.IsAbsolute = true;<br>
} else {<br>
E = readExpr();<br>
}<br>
if (Op == "+=")<br>
E = [=](uint64_t Dot) { return getSymbolValue(Name, Dot) + E(Dot); };<br>
- return new SymbolAssignment(Name, E, IsAbsolute);<br>
+ return new SymbolAssignment(Name, E);<br>
}<br>
<br>
// This is an operator-precedence parser to parse a linker<br>
@@ -1671,8 +1670,9 @@ Expr ScriptParser::readPrimary() {<br>
}<br>
if (Tok == "ALIGNOF") {<br>
StringRef Name = readParenLiteral();<br>
- return<br>
- [=](uint64_t Dot) { return ScriptBase-><wbr>getOutputSectionAlign(Name); };<br>
+ return {<br>
+ [=](uint64_t Dot) { return ScriptBase-><wbr>getOutputSectionAlign(Name); },<br>
+ true};<br>
}<br>
if (Tok == "SIZEOF_HEADERS")<br>
return [=](uint64_t Dot) { return ScriptBase->getHeaderSize(); };<br>
<br>
Modified: lld/trunk/ELF/LinkerScript.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=285608&r1=285607&r2=285608&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>LinkerScript.h?rev=285608&r1=<wbr>285607&r2=285608&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/LinkerScript.h (original)<br>
+++ lld/trunk/ELF/LinkerScript.h Mon Oct 31 12:43:38 2016<br>
@@ -37,7 +37,17 @@ class InputSectionData;<br>
// ScriptParser::readExpr reads an expression and returns an Expr.<br>
// Later, we evaluate the expression by calling the function<br>
// with the value of special context variable ".".<br>
-typedef std::function<uint64_t(uint64_<wbr>t)> Expr;<br>
+struct Expr {<br>
+ std::function<uint64_t(uint64_<wbr>t)> Val;<br>
+ bool IsAbsolute;<br>
+ uint64_t operator()(uint64_t Dot) const { return Val(Dot); }<br>
+ operator bool() const { return (bool)Val; }<br>
+<br>
+ template <typename T><br>
+ Expr(T Val, bool IsAbsolute) : Val(Val), IsAbsolute(IsAbsolute) {}<br>
+ template <typename T> Expr(T V) : Expr(V, false) {}<br>
+ Expr() : Expr(nullptr) {}<br>
+};<br></blockquote><div><br></div><div>I really liked the fact that an expression is compiled to a lambda in our linker script processor. Isn't there any other way to do this?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
// Parses a linker script. Calling this function updates<br>
// Config and ScriptConfig.<br>
@@ -64,9 +74,8 @@ struct BaseCommand {<br>
<br>
// This represents ". = <expr>" or "<symbol> = <expr>".<br>
struct SymbolAssignment : BaseCommand {<br>
- SymbolAssignment(StringRef Name, Expr E, bool IsAbsolute)<br>
- : BaseCommand(AssignmentKind), Name(Name), Expression(E),<br>
- IsAbsolute(IsAbsolute) {}<br>
+ SymbolAssignment(StringRef Name, Expr E)<br>
+ : BaseCommand(AssignmentKind), Name(Name), Expression(E) {}<br>
static bool classof(const BaseCommand *C);<br>
<br>
// The LHS of an expression. Name is either a symbol name or ".".<br>
@@ -79,7 +88,6 @@ struct SymbolAssignment : BaseCommand {<br>
// Command attributes for PROVIDE, HIDDEN and PROVIDE_HIDDEN.<br>
bool Provide = false;<br>
bool Hidden = false;<br>
- bool IsAbsolute;<br>
};<br>
<br>
// Linker scripts allow additional constraints to be put on ouput sections.<br>
<br>
Added: lld/trunk/test/ELF/<wbr>linkerscript/absolute-expr.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/absolute-expr.s?rev=285608&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/test/ELF/<wbr>linkerscript/absolute-expr.s?<wbr>rev=285608&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/test/ELF/<wbr>linkerscript/absolute-expr.s (added)<br>
+++ lld/trunk/test/ELF/<wbr>linkerscript/absolute-expr.s Mon Oct 31 12:43:38 2016<br>
@@ -0,0 +1,17 @@<br>
+# REQUIRES: x86<br>
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o<br>
+# RUN: echo "SECTIONS { \<br>
+# RUN: .text : { bar = ALIGNOF(.text); *(.text) } \<br>
+# RUN: };" > %t.script<br>
+# RUN: ld.lld -o %t.so --script %t.script %t.o -shared<br>
+# RUN: llvm-readobj -t %t.so | FileCheck %s<br>
+<br>
+# CHECK: Symbol {<br>
+# CHECK: Name: bar<br>
+# CHECK-NEXT: Value: 0x4<br>
+# CHECK-NEXT: Size: 0<br>
+# CHECK-NEXT: Binding: Global<br>
+# CHECK-NEXT: Type: None<br>
+# CHECK-NEXT: Other: 0<br>
+# CHECK-NEXT: Section: Absolute<br>
+# CHECK-NEXT: }<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>