[lld] r276780 - [ELF] - Linkerscript: implemented ALIGN modificatior of output sections.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 26 11:06:30 PDT 2016


Author: grimar
Date: Tue Jul 26 13:06:29 2016
New Revision: 276780

URL: http://llvm.org/viewvc/llvm-project?rev=276780&view=rev
Log:
[ELF] - Linkerscript: implemented ALIGN modificatior of output sections.

Output section description can contain ALIGN modificator:
https://sourceware.org/binutils/docs/ld/Output-Section-Description.html#Output-Section-Description

Patch implements it.

Differential revision: https://reviews.llvm.org/D22674

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/LinkerScript.h
    lld/trunk/test/ELF/linkerscript/linkerscript-align.s

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=276780&r1=276779&r2=276780&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Jul 26 13:06:29 2016
@@ -226,6 +226,9 @@ void LinkerScript<ELFT>::assignAddresses
       if (Cmd->AddrExpr)
         Dot = Cmd->AddrExpr(Dot);
 
+      if (Cmd->AlignExpr)
+        Sec->updateAlignment(Cmd->AlignExpr(Dot));
+
       if ((Sec->getFlags() & SHF_TLS) && Sec->getType() == SHT_NOBITS) {
         uintX_t TVA = Dot + ThreadBssOffset;
         TVA = alignTo(TVA, Sec->getAlignment());
@@ -433,6 +436,7 @@ private:
   std::vector<StringRef> readOutputSectionPhdrs();
   unsigned readPhdrType();
   void readProvide(bool Hidden);
+  void readAlign(OutputSectionCommand *Cmd);
 
   Expr readExpr();
   Expr readExpr1(Expr Lhs, int MinPrec);
@@ -671,6 +675,12 @@ void ScriptParser::readKeep(OutputSectio
   expect(")");
 }
 
+void ScriptParser::readAlign(OutputSectionCommand *Cmd) {
+  expect("(");
+  Cmd->AlignExpr = readExpr();
+  expect(")");
+}
+
 void ScriptParser::readOutputSectionDescription(StringRef OutSec) {
   OutputSectionCommand *Cmd = new OutputSectionCommand(OutSec);
   Opt.Commands.emplace_back(Cmd);
@@ -682,6 +692,9 @@ void ScriptParser::readOutputSectionDesc
 
   expect(":");
 
+  if (skip("ALIGN"))
+    readAlign(Cmd);
+
   // Parse constraints.
   if (skip("ONLY_IF_RO"))
     Cmd->Constraint = ConstraintKind::ReadOnly;

Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=276780&r1=276779&r2=276780&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Tue Jul 26 13:06:29 2016
@@ -73,6 +73,7 @@ struct OutputSectionCommand : BaseComman
   static bool classof(const BaseCommand *C);
   StringRef Name;
   Expr AddrExpr;
+  Expr AlignExpr;
   std::vector<std::unique_ptr<BaseCommand>> Commands;
   std::vector<StringRef> Phdrs;
   std::vector<uint8_t> Filler;

Modified: lld/trunk/test/ELF/linkerscript/linkerscript-align.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/linkerscript-align.s?rev=276780&r1=276779&r2=276780&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/linkerscript-align.s (original)
+++ lld/trunk/test/ELF/linkerscript/linkerscript-align.s Tue Jul 26 13:06:29 2016
@@ -1,6 +1,7 @@
 # REQUIRES: x86
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
 
+## Check that ALIGN command workable using location counter
 # RUN: echo "SECTIONS { \
 # RUN:  . = 0x10000; \
 # RUN:  .aaa : \
@@ -27,6 +28,25 @@
 # CHECK-NEXT:   2 .bbb          00000008 0000000000011000 DATA
 # CHECK-NEXT:   3 .ccc          00000008 0000000000014000 DATA
 
+## Check output sections ALIGN modificator
+# RUN: echo "SECTIONS { \
+# RUN:  . = 0x10000; \
+# RUN:  .aaa : \
+# RUN:  { \
+# RUN:   *(.aaa) \
+# RUN:  } \
+# RUN:  .bbb : ALIGN(4096) \
+# RUN:  { \
+# RUN:   *(.bbb) \
+# RUN:  } \
+# RUN:  .ccc : ALIGN(4096 * 4) \
+# RUN:  { \
+# RUN:   *(.ccc) \
+# RUN:  } \
+# RUN: }" > %t2.script
+# RUN: ld.lld -o %t2 --script %t2.script %t
+# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
+
 .global _start
 _start:
  nop




More information about the llvm-commits mailing list