[lld] r332656 - Make ALIGN work with -r in linker scripts

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu May 17 13:22:39 PDT 2018


Author: ruiu
Date: Thu May 17 13:22:39 2018
New Revision: 332656

URL: http://llvm.org/viewvc/llvm-project?rev=332656&view=rev
Log:
Make ALIGN work with -r in linker scripts

Patch by Mark Kettenis.

Make ALIGN work in linker scripts used with the -r option. This works in
GNU ld (ld.bfd) and is used to generate the "random gap" object for
linking the OpenBSD kernel.

Differential Revision: https://reviews.llvm.org/D46839

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

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=332656&r1=332655&r2=332656&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu May 17 13:22:39 2018
@@ -868,6 +868,11 @@ void LinkerScript::adjustSectionsBeforeS
     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 @@ void LinkerScript::adjustSectionsAfterSo
           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());
     }
   }
 

Added: lld/trunk/test/ELF/linkerscript/align-r.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/align-r.test?rev=332656&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/align-r.test (added)
+++ lld/trunk/test/ELF/linkerscript/align-r.test Thu May 17 13:22:39 2018
@@ -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) }
+}




More information about the llvm-commits mailing list