[PATCH] D37720: Correct ALIGN expression when inside a section.

Rafael Ávila de Espíndola via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 11 16:16:33 PDT 2017


rafael created this revision.
Herald added a subscriber: emaste.

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 algins the address.

This changes lld to align the final address.


https://reviews.llvm.org/D37720

Files:
  ELF/LinkerScript.cpp
  test/ELF/linkerscript/align.s


Index: test/ELF/linkerscript/align.s
===================================================================
--- test/ELF/linkerscript/align.s
+++ test/ELF/linkerscript/align.s
@@ -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
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -141,7 +141,7 @@
     Sym->Value = V.getValue();
   } else {
     Sym->Section = V.Sec;
-    Sym->Value = alignTo(V.Val, V.Alignment);
+    Sym->Value = V.getValue() - V.getSecAddr();
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37720.114729.patch
Type: text/x-patch
Size: 1225 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170911/54435f77/attachment.bin>


More information about the llvm-commits mailing list