[PATCH] D46839: [lld] Make ALIGN work with -r in linker scripts

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 17 13:26:33 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL332656: Make ALIGN work with -r in linker scripts (authored by ruiu, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D46839?vs=146910&id=147381#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46839

Files:
  lld/trunk/ELF/LinkerScript.cpp
  lld/trunk/test/ELF/linkerscript/align-r.test


Index: lld/trunk/test/ELF/linkerscript/align-r.test
===================================================================
--- lld/trunk/test/ELF/linkerscript/align-r.test
+++ lld/trunk/test/ELF/linkerscript/align-r.test
@@ -0,0 +1,21 @@
+# REQUIRES: x86
+
+## Check output section ALIGN modifier with -r
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/align.s -o %t1.o
+# RUN: ld.lld -r -o %t2.o --script %s %t1.o
+# RUN: llvm-readelf -s %t2.o | FileCheck %s
+
+# CHECK:      Section Headers:
+# CHECK-NEXT: Name Type     Address          Off    Size   ES Flg Lk Inf Al
+# CHECK-NEXT:      NULL     0000000000000000 000000 000000 00
+# CHECK-NEXT: .aaa PROGBITS 0000000000000000 000040 000008 00   A  0   0   1
+# CHECK-NEXT: .bbb PROGBITS 0000000000000000 001000 000008 00   A  0   0  4096
+# CHECK-NEXT: .ccc PROGBITS 0000000000000000 004000 000008 00   A  0   0  16384
+
+SECTIONS {
+  . = 0x10000;
+  .aaa : { *(.aaa) }
+  .bbb : ALIGN(4096) { *(.bbb) }
+  .ccc : ALIGN(4096 * 4) { *(.ccc) }
+}
Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -868,6 +868,11 @@
     if (!Sec)
       continue;
 
+    // Handle align (e.g. ".foo : ALIGN(16) { ... }").
+    if (Sec->AlignExpr)
+      Sec->Alignment =
+          std::max<uint32_t>(Sec->Alignment, Sec->AlignExpr().getValue());
+
     // A live output section means that some input section was added to it. It
     // might have been removed (if it was empty synthetic section), but we at
     // least know the flags.
@@ -906,10 +911,6 @@
           error("memory region '" + Sec->LMARegionName + "' not declared");
       }
       Sec->MemRegion = findMemoryRegion(Sec);
-      // Handle align (e.g. ".foo : ALIGN(16) { ... }").
-      if (Sec->AlignExpr)
-        Sec->Alignment =
-            std::max<uint32_t>(Sec->Alignment, Sec->AlignExpr().getValue());
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46839.147381.patch
Type: text/x-patch
Size: 1980 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180517/d24a1b91/attachment.bin>


More information about the llvm-commits mailing list