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

Mark Kettenis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 15 13:31:07 PDT 2018


kettenis updated this revision to Diff 146910.
kettenis added a comment.

New diff that fixes the regression test.


https://reviews.llvm.org/D46839

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
@@ -32,15 +32,26 @@
 # CHECK-NEXT:   2 .bbb          00000008 0000000000011000 DATA
 # CHECK-NEXT:   3 .ccc          00000008 0000000000014000 DATA
 
-## Check output sections ALIGN modificator
+## Check output section ALIGN modifier
 # RUN: echo "SECTIONS {                    \
 # RUN:  . = 0x10000;                       \
 # RUN:  .aaa : { *(.aaa) }                 \
 # RUN:  .bbb : ALIGN(4096) { *(.bbb) }     \
 # RUN:  .ccc : ALIGN(4096 * 4) { *(.ccc) } \
 # RUN: }" > %t2.script
 # RUN: ld.lld -o %t2 --script %t2.script %t
 # RUN: llvm-objdump -section-headers %t2 | FileCheck %s
+
+## Check output section ALIGN modifier with -r
+# RUN: ld.lld -r -o %t2.o --script %t2.script %t
+# RUN: llvm-readelf -s %t2.o | FileCheck -check-prefix ALIGN %s
+
+# ALIGN:      Section Headers:
+# ALIGN-NEXT: Name Type     Address          Off    Size   ES Flg Lk Inf Al
+# ALIGN-NEXT:      NULL     0000000000000000 000000 000000 00
+# ALIGN-NEXT: .aaa PROGBITS 0000000000000000 000040 000008 00   A  0   0   1
+# ALIGN-NEXT: .bbb PROGBITS 0000000000000000 001000 000008 00   A  0   0  4096
+# ALIGN-NEXT: .ccc PROGBITS 0000000000000000 004000 000008 00   A  0   0  16384
 
 ## Check use of variables in align expressions:
 # RUN: echo "VAR = 0x1000;                                  \
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ 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.146910.patch
Type: text/x-patch
Size: 2385 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180515/67013a9f/attachment.bin>


More information about the llvm-commits mailing list