[lld] r313777 - Add a special case for trivial alignment.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 20 10:43:44 PDT 2017


Author: rafael
Date: Wed Sep 20 10:43:44 2017
New Revision: 313777

URL: http://llvm.org/viewvc/llvm-project?rev=313777&view=rev
Log:
Add a special case for trivial alignment.

Normally to find the offset of a value in a section, we have to
compute the value since the alignment is defined on the final address.

If the alignment is trivial, we can skip the value computation. This
allows us to know the offset even in cases where we cannot yet know
the value.

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/test/ELF/linkerscript/early-assign-symbol.s

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=313777&r1=313776&r2=313777&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Sep 20 10:43:44 2017
@@ -71,6 +71,11 @@ uint64_t ExprValue::getSecAddr() const {
 }
 
 uint64_t ExprValue::getSectionOffset() const {
+  // If the alignment is trivial, we don't have to compute the full
+  // value to know the offset. This allows this function to succeed in
+  // cases where the output section is not yet known.
+  if (Alignment == 1)
+    return Val;
   return getValue() - getSecAddr();
 }
 

Modified: lld/trunk/test/ELF/linkerscript/early-assign-symbol.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/early-assign-symbol.s?rev=313777&r1=313776&r2=313777&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/early-assign-symbol.s (original)
+++ lld/trunk/test/ELF/linkerscript/early-assign-symbol.s Wed Sep 20 10:43:44 2017
@@ -1,9 +1,6 @@
 # REQUIRES: x86
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
 
-# RUN: echo "SECTIONS { aaa = 1 + ABSOLUTE(foo - 1); .text  : { *(.text*) } }" > %t1.script
-# RUN: not ld.lld -o %t --script %t1.script %t.o 2>&1 | FileCheck %s
-
 # RUN: echo "SECTIONS { aaa = ABSOLUTE(foo - 1) + 1; .text  : { *(.text*) } }" > %t2.script
 # RUN: not ld.lld -o %t --script %t2.script %t.o 2>&1 | FileCheck %s
 
@@ -12,9 +9,18 @@
 
 # CHECK: error: {{.*}}.script:1: unable to evaluate expression: input section .text has no output section assigned
 
-# Simple case that we can handle.
+# Simple cases that we can handle.
+
+# RUN: echo "SECTIONS { aaa = 1 + ABSOLUTE(foo - 1); .text  : { *(.text*) } }" > %t.script
+# RUN: ld.lld -o %t --script %t.script %t.o
+# RUN: llvm-objdump -t %t | FileCheck --check-prefix=VAL %s
+
 # RUN: echo "SECTIONS { aaa = ABSOLUTE(foo); .text  : { *(.text*) } }" > %t4.script
 # RUN: ld.lld -o %t --script %t4.script %t.o
+# RUN: llvm-objdump -t %t | FileCheck --check-prefix=VAL %s
+
+# VAL: 0000000000000000 .text 00000000 foo
+# VAL: 0000000000000000 *ABS* 00000000 aaa
 
 .section .text
 .globl foo




More information about the llvm-commits mailing list