[PATCH] D23063: [ELF] - Linkerscript: implemented SUBALIGN() command.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 18 00:29:43 PDT 2016


grimar updated this revision to Diff 68489.
grimar added a comment.

- Addressed review comments.


https://reviews.llvm.org/D23063

Files:
  ELF/LinkerScript.cpp
  ELF/LinkerScript.h
  test/ELF/linkerscript/linkerscript-subalign.s

Index: test/ELF/linkerscript/linkerscript-subalign.s
===================================================================
--- test/ELF/linkerscript/linkerscript-subalign.s
+++ test/ELF/linkerscript/linkerscript-subalign.s
@@ -0,0 +1,43 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+
+# RUN: echo "SECTIONS { .aaa : { *(.aaa.*) } }" > %t1.script
+# RUN: ld.lld -o %t1 --script %t1.script %t1.o
+# RUN: llvm-objdump -s %t1 | FileCheck -check-prefix=NOALIGN %s
+# NOALIGN:      Contents of section .aaa:
+# NOALIGN-NEXT:   01000000 00000000 00000000 00000000
+# NOALIGN-NEXT:   00000000 00000000 00000000 00000000
+# NOALIGN-NEXT:   02000000 00000000 00000000 00000000
+# NOALIGN-NEXT:   00000000 00000000 00000000 00000000
+# NOALIGN-NEXT:   03000000 00000000 00000000 00000000
+# NOALIGN-NEXT:   00000000 00000000 00000000 00000000
+# NOALIGN-NEXT:   00000000 00000000 00000000 00000000
+# NOALIGN-NEXT:   00000000 00000000 00000000 00000000
+# NOALIGN-NEXT:   04000000 00000000
+
+# RUN: echo "SECTIONS { .aaa : SUBALIGN(1) { *(.aaa.*) } }" > %t2.script
+# RUN: ld.lld -o %t2 --script %t2.script %t1.o
+# RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=SUBALIGN %s
+# SUBALIGN: Contents of section .aaa:
+# SUBALIGN:   01000000 00000000 02000000 00000000
+# SUBALIGN:   03000000 00000000 04000000 00000000
+
+.global _start
+_start:
+ nop
+
+.section .aaa.1, "a"
+.align 16
+.quad 1
+
+.section .aaa.2, "a"
+.align 32
+.quad 2
+
+.section .aaa.3, "a"
+.align 64
+.quad 3
+
+.section .aaa.4, "a"
+.align 128
+.quad 4
Index: ELF/LinkerScript.h
===================================================================
--- ELF/LinkerScript.h
+++ ELF/LinkerScript.h
@@ -84,6 +84,7 @@
   Expr AddrExpr;
   Expr AlignExpr;
   Expr LmaExpr;
+  Expr SubalignExpr;
   std::vector<std::unique_ptr<BaseCommand>> Commands;
   std::vector<StringRef> Phdrs;
   std::vector<uint8_t> Filler;
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -283,8 +283,13 @@
       std::tie(OutSec, IsNew) = Factory.create(Head, Cmd->Name);
       if (IsNew)
         OutputSections->push_back(OutSec);
-      for (InputSectionBase<ELFT> *Sec : V)
+
+      uint32_t Subalign = Cmd->SubalignExpr ? Cmd->SubalignExpr(0) : -1;
+      for (InputSectionBase<ELFT> *Sec : V) {
+        if (Cmd->SubalignExpr)
+          Sec->Alignment = Subalign;
         OutSec->addSection(Sec);
+      }
     }
   }
 
@@ -936,6 +941,8 @@
     Cmd->LmaExpr = readParenExpr();
   if (skip("ALIGN"))
     Cmd->AlignExpr = readParenExpr();
+  if (skip("SUBALIGN"))
+    Cmd->SubalignExpr = readParenExpr();
 
   // Parse constraints.
   if (skip("ONLY_IF_RO"))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23063.68489.patch
Type: text/x-patch
Size: 2819 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160818/e4a4051b/attachment.bin>


More information about the llvm-commits mailing list