[llvm-branch-commits] [lld] r369743 - Merging r368145:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Aug 23 02:44:43 PDT 2019


Author: hans
Date: Fri Aug 23 02:44:42 2019
New Revision: 369743

URL: http://llvm.org/viewvc/llvm-project?rev=369743&view=rev
Log:
Merging r368145:
------------------------------------------------------------------------
r368145 | ruiu | 2019-08-07 12:16:21 +0200 (Wed, 07 Aug 2019) | 3 lines

Handle /align option.

Differential Revision: https://reviews.llvm.org/D65736
------------------------------------------------------------------------

Added:
    lld/branches/release_90/test/COFF/align.s
      - copied unchanged from r368145, lld/trunk/test/COFF/align.s
Modified:
    lld/branches/release_90/   (props changed)
    lld/branches/release_90/COFF/Config.h
    lld/branches/release_90/COFF/Driver.cpp
    lld/branches/release_90/COFF/Writer.cpp

Propchange: lld/branches/release_90/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 23 02:44:42 2019
@@ -1 +1 @@
-/lld/trunk:366445,366500,366504,366780,366784,367836-367837,368041,368078
+/lld/trunk:366445,366500,366504,366780,366784,367836-367837,368041,368078,368145

Modified: lld/branches/release_90/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_90/COFF/Config.h?rev=369743&r1=369742&r2=369743&view=diff
==============================================================================
--- lld/branches/release_90/COFF/Config.h (original)
+++ lld/branches/release_90/COFF/Config.h Fri Aug 23 02:44:42 2019
@@ -189,6 +189,7 @@ struct Configuration {
   // Used for /thinlto-object-suffix-replace:
   std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
 
+  uint64_t align = 4096;
   uint64_t imageBase = -1;
   uint64_t fileAlign = 512;
   uint64_t stackReserve = 1024 * 1024;

Modified: lld/branches/release_90/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_90/COFF/Driver.cpp?rev=369743&r1=369742&r2=369743&view=diff
==============================================================================
--- lld/branches/release_90/COFF/Driver.cpp (original)
+++ lld/branches/release_90/COFF/Driver.cpp Fri Aug 23 02:44:42 2019
@@ -36,6 +36,7 @@
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/LEB128.h"
+#include "llvm/Support/MathExtras.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/TarWriter.h"
@@ -1421,6 +1422,13 @@ void LinkerDriver::link(ArrayRef<const c
   for (auto *arg : args.filtered(OPT_section))
     parseSection(arg->getValue());
 
+  // Handle /align
+  if (auto *arg = args.getLastArg(OPT_align)) {
+    parseNumbers(arg->getValue(), &config->align);
+    if (!isPowerOf2_64(config->align))
+      error("/align: not a power of two: " + StringRef(arg->getValue()));
+  }
+
   // Handle /aligncomm
   for (auto *arg : args.filtered(OPT_aligncomm))
     parseAligncomm(arg->getValue());

Modified: lld/branches/release_90/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_90/COFF/Writer.cpp?rev=369743&r1=369742&r2=369743&view=diff
==============================================================================
--- lld/branches/release_90/COFF/Writer.cpp (original)
+++ lld/branches/release_90/COFF/Writer.cpp Fri Aug 23 02:44:42 2019
@@ -1205,9 +1205,11 @@ void Writer::assignAddresses() {
   sizeOfHeaders +=
       config->is64() ? sizeof(pe32plus_header) : sizeof(pe32_header);
   sizeOfHeaders = alignTo(sizeOfHeaders, config->fileAlign);
-  uint64_t rva = pageSize; // The first page is kept unmapped.
   fileSize = sizeOfHeaders;
 
+  // The first page is kept unmapped.
+  uint64_t rva = alignTo(sizeOfHeaders, config->align);
+
   for (OutputSection *sec : outputSections) {
     if (sec == relocSec)
       addBaserels();
@@ -1237,10 +1239,10 @@ void Writer::assignAddresses() {
     sec->header.SizeOfRawData = rawSize;
     if (rawSize != 0)
       sec->header.PointerToRawData = fileSize;
-    rva += alignTo(virtualSize, pageSize);
+    rva += alignTo(virtualSize, config->align);
     fileSize += alignTo(rawSize, config->fileAlign);
   }
-  sizeOfImage = alignTo(rva, pageSize);
+  sizeOfImage = alignTo(rva, config->align);
 
   // Assign addresses to sections in MergeChunks.
   for (MergeChunk *mc : MergeChunk::instances)
@@ -1309,7 +1311,7 @@ template <typename PEHeaderTy> void Writ
   pe->MinorLinkerVersion = 0;
 
   pe->ImageBase = config->imageBase;
-  pe->SectionAlignment = pageSize;
+  pe->SectionAlignment = config->align;
   pe->FileAlignment = config->fileAlign;
   pe->MajorImageVersion = config->majorImageVersion;
   pe->MinorImageVersion = config->minorImageVersion;




More information about the llvm-branch-commits mailing list