[lld] r370629 - [ELF] Align SHT_LLVM_PART_EHDR to a maximum page size boundary

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 2 01:49:50 PDT 2019


Author: maskray
Date: Mon Sep  2 01:49:50 2019
New Revision: 370629

URL: http://llvm.org/viewvc/llvm-project?rev=370629&view=rev
Log:
[ELF] Align SHT_LLVM_PART_EHDR to a maximum page size boundary

Fixes https://bugs.chromium.org/p/chromium/issues/detail?id=998712

SHT_LLVM_PART_EHDR marks the start of a partition. The partition
sections will be extracted to a separate file. Align to the next maximum
page size boundary so that we can find the ELF header at the start. We
cannot benefit from overlapping p_offset ranges with the previous
segment anyway.

It seems we lack some llvm-objcopy --extract-main-partition and
--extract-partition sanity checks. It may place EHDR at the start
even if p_offset if non zero. Anyway, the lld change is justified for
the reasons above.

Reviewed By: ruiu

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

Modified:
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/ELF/partitions.s

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=370629&r1=370628&r2=370629&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Sep  2 01:49:50 2019
@@ -2223,13 +2223,21 @@ template <class ELFT> void Writer<ELFT>:
       // the next maximum page size boundary on transitions between executable
       // and non-executable segments.
       //
+      // SHT_LLVM_PART_EHDR marks the start of a partition. The partition
+      // sections will be extracted to a separate file. Align to the next
+      // maximum page size boundary so that we can find the ELF header at the
+      // start. We cannot benefit from overlapping p_offset ranges with the
+      // previous segment anyway.
+      //
       // TODO Enable this technique on all targets.
       bool enable = config->emachine != EM_HEXAGON &&
                     config->emachine != EM_MIPS &&
                     config->emachine != EM_X86_64;
 
-      if (!enable || (config->zSeparateCode && prev &&
-                      (prev->p_flags & PF_X) != (p->p_flags & PF_X)))
+      if (!enable ||
+          (config->zSeparateCode && prev &&
+           (prev->p_flags & PF_X) != (p->p_flags & PF_X)) ||
+          cmd->type == SHT_LLVM_PART_EHDR)
         cmd->addrExpr = [] {
           return alignTo(script->getDot(), config->maxPageSize);
         };

Modified: lld/trunk/test/ELF/partitions.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/partitions.s?rev=370629&r1=370628&r2=370629&view=diff
==============================================================================
--- lld/trunk/test/ELF/partitions.s (original)
+++ lld/trunk/test/ELF/partitions.s Mon Sep  2 01:49:50 2019
@@ -1,13 +1,20 @@
-// REQUIRES: x86
+// REQUIRES: aarch64, x86
 // RUN: llvm-mc %s -o %t.o -filetype=obj --triple=x86_64-unknown-linux
+// RUN: ld.lld %t.o -o %t --export-dynamic --gc-sections -z max-page-size=65536
+// RUN: llvm-readelf -S -s %t | FileCheck %s
+
+// RUN: llvm-mc %s -o %t.o -filetype=obj --triple=aarch64
 // RUN: ld.lld %t.o -o %t --export-dynamic --gc-sections
 // RUN: llvm-readelf -S -s %t | FileCheck %s
 
 // This is basically lld/docs/partitions.dot in object file form.
 // Test that the sections are correctly allocated to partitions.
+// part1 and part2 should be aligned to a maximum page size boundary.
 
 // CHECK: [[MAIN:[0-9]+]]] .text
+// CHECK: part1 LOOS+0xFFF4C06 {{[0-9a-f]+}}0000 {{[0-9a-f]+}}0000
 // CHECK: [[P1:[0-9]+]]] .text
+// CHECK: part2 LOOS+0xFFF4C06 {{[0-9a-f]+}}0000 {{[0-9a-f]+}}0000
 // CHECK: [[P2:[0-9]+]]] .text
 
 // CHECK: Symbol table '.symtab'
@@ -30,21 +37,21 @@
 .section .text._start,"ax", at progbits
 .globl _start
 _start:
-call f3
+.quad f3
 
 .section .text.f1,"ax", at progbits
 .globl f1
 f1:
-call f3
-call f4
-call f5
+.quad f3
+.quad f4
+.quad f5
 
 .section .text.f2,"ax", at progbits
 .globl f2
 f2:
-call f3
-call f5
-call f6
+.quad f3
+.quad f5
+.quad f6
 
 .section .text.f3,"ax", at progbits
 f3:




More information about the llvm-commits mailing list