[lld] r312979 - Correct ALIGN expression when inside a section.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 11 16:44:53 PDT 2017


Author: rafael
Date: Mon Sep 11 16:44:53 2017
New Revision: 312979

URL: http://llvm.org/viewvc/llvm-project?rev=312979&view=rev
Log:
Correct ALIGN expression when inside a section.

When given

foobar = ALIGN(., 0x100);

my expectation from what the manual says is that the final address of
foobar will be aligned. It seems that bfd aligns the offset in the
section, which causes some odd results if the section is not 0x100
aligned. Gold aligns the address.

This changes lld to align the final address.

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/test/ELF/linkerscript/align.s

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=312979&r1=312978&r2=312979&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Mon Sep 11 16:44:53 2017
@@ -141,7 +141,7 @@ void LinkerScript::assignSymbol(SymbolAs
     Sym->Value = V.getValue();
   } else {
     Sym->Section = V.Sec;
-    Sym->Value = alignTo(V.Val, V.Alignment);
+    Sym->Value = V.getValue() - V.getSecAddr();
   }
 }
 

Modified: lld/trunk/test/ELF/linkerscript/align.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/align.s?rev=312979&r1=312978&r2=312979&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/align.s (original)
+++ lld/trunk/test/ELF/linkerscript/align.s Mon Sep 11 16:44:53 2017
@@ -81,6 +81,20 @@
 # RUN: ld.lld -o %t5 --script %t.script %t
 # RUN: llvm-objdump -section-headers %t5 | FileCheck %s -check-prefix=ZERO
 
+
+# RUN: echo "SECTIONS {                              \
+# RUN:  . = 0xff8;                                   \
+# RUN:  .aaa : { *(.aaa) foo = ALIGN(., 0x100); bar = .; } \
+# RUN:  .bbb : { *(.bbb); } \
+# RUN:  .ccc : { *(.ccc); } \
+# RUN:  .text : { *(.text); } \
+# RUN: }" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=OFFSET %s
+
+# OFFSET: 0000000000001000         .aaa            00000000 foo
+# OFFSET: 0000000000001000         .aaa            00000000 bar
+
 .global _start
 _start:
  nop




More information about the llvm-commits mailing list