[PATCH] D46839: [lld] Make ALIGN work with -r in linker scripts
Mark Kettenis via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 14 10:58:10 PDT 2018
kettenis created this revision.
kettenis added reviewers: ruiu, grimar, ikudrin, jhenderson.
Herald added subscribers: llvm-commits, krytarowski, arichardson, emaste.
Herald added a reviewer: espindola.
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.
Repository:
rLLD LLVM Linker
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
@@ -42,6 +42,23 @@
# RUN: ld.lld -o %t2 --script %t2.script %t
# RUN: llvm-objdump -section-headers %t2 | FileCheck %s
+## Check output sections ALIGN modificator with -r
+# RUN: echo "SECTIONS { \
+# RUN: . = 0x10000; \
+# RUN: .aaa : { *(.aaa) } \
+# RUN: .bbb : ALIGN(4096) { *(.bbb) } \
+# RUN: .ccc : ALIGN(4096 * 4) { *(.ccc) } \
+# RUN: }" > %t6.script
+# RUN: ld.lld -r -o %t2 --script %t2.script %t
+# RUN: llvm-readelf -s %t2 | 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; \
# RUN: __code_base__ = 0x10000; \
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.146641.patch
Type: text/x-patch
Size: 2233 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180514/bddbdf54/attachment.bin>
More information about the llvm-commits
mailing list