[lld] r369507 - Reland D65242 "[ELF] More dynamic relocation packing""

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 21 02:21:38 PDT 2019


Author: maskray
Date: Wed Aug 21 02:21:37 2019
New Revision: 369507

URL: http://llvm.org/viewvc/llvm-project?rev=369507&view=rev
Log:
Reland D65242 "[ELF] More dynamic relocation packing""

This fixed a bug in r369488. When config->isRela is false, i->r_addend
is not initialized (see encodeDynamicReloc). So we should check
config->isRela before accessing r_addend:

- if (j - i < 3 || i->r_addend)
+ if (j - i < 3 || (config->isRela && i->r_addend != 0))

Original description:

Currently, with Android dynamic relocation packing, only relative
relocations are grouped together. This patch implements similar
packing for non-relative relocations.

The implementation groups non-relative relocations with the same
r_info and r_addend, if using RELA. By requiring a minimum group
size of 3, this achieves smaller relocation sections. Building Android
for an ARM32 device, I see the total size of /system/lib decrease by
392 KB.

Grouping by r_info also allows the runtime dynamic linker to implement
an 1-entry cache to reduce the number of symbol lookup required. With
such 1-entry cache implemented on Android, I'm seeing 10% to 20%
reduction in total time spent in runtime linker for several executables
that I tested.

As a simple correctness check, I've also built x86_64 Android and booted
successfully.

Differential Revision: https://reviews.llvm.org/D65242
Patch by Vic Yang

Modified:
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/test/ELF/pack-dyn-relocs.s

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=369507&r1=369506&r2=369507&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Wed Aug 21 02:21:37 2019
@@ -1702,6 +1702,56 @@ bool AndroidPackedRelocationSection<ELFT
       relativeGroups.emplace_back(std::move(group));
   }
 
+  // For non-relative relocations, we would like to:
+  //   1. Have relocations with the same symbol offset to be consecutive, so
+  //      that the runtime linker can speed-up symbol lookup by implementing an
+  //      1-entry cache.
+  //   2. Group relocations by r_info to reduce the size of the relocation
+  //      section.
+  // Since the symbol offset is the high bits in r_info, sorting by r_info
+  // allows us to do both.
+  //
+  // For Rela, we also want to sort by r_addend when r_info is the same. This
+  // enables us to group by r_addend as well.
+  llvm::stable_sort(nonRelatives, [](const Elf_Rela &a, const Elf_Rela &b) {
+    if (a.r_info != b.r_info)
+      return a.r_info < b.r_info;
+    if (config->isRela)
+      return a.r_addend < b.r_addend;
+    return false;
+  });
+
+  // Group relocations with the same r_info. Note that each group emits a group
+  // header and that may make the relocation section larger. It is hard to
+  // estimate the size of a group header as the encoded size of that varies
+  // based on r_info. However, we can approximate this trade-off by the number
+  // of values encoded. Each group header contains 3 values, and each relocation
+  // in a group encodes one less value, as compared to when it is not grouped.
+  // Therefore, we only group relocations if there are 3 or more of them with
+  // the same r_info.
+  //
+  // For Rela, the addend for most non-relative relocations is zero, and thus we
+  // can usually get a smaller relocation section if we group relocations with 0
+  // addend as well.
+  std::vector<Elf_Rela> ungroupedNonRelatives;
+  std::vector<std::vector<Elf_Rela>> nonRelativeGroups;
+  for (auto i = nonRelatives.begin(), e = nonRelatives.end(); i != e;) {
+    auto j = i + 1;
+    while (j != e && i->r_info == j->r_info &&
+           (!config->isRela || i->r_addend == j->r_addend))
+      ++j;
+    if (j - i < 3 || (config->isRela && i->r_addend != 0))
+      ungroupedNonRelatives.insert(ungroupedNonRelatives.end(), i, j);
+    else
+      nonRelativeGroups.emplace_back(i, j);
+    i = j;
+  }
+
+  // Sort ungrouped relocations by offset to minimize the encoded length.
+  llvm::sort(ungroupedNonRelatives, [](const Elf_Rela &a, const Elf_Rela &b) {
+    return a.r_offset < b.r_offset;
+  });
+
   unsigned hasAddendIfRela =
       config->isRela ? RELOCATION_GROUP_HAS_ADDEND_FLAG : 0;
 
@@ -1756,14 +1806,23 @@ bool AndroidPackedRelocationSection<ELFT
     }
   }
 
-  // Finally the non-relative relocations.
-  llvm::sort(nonRelatives, [](const Elf_Rela &a, const Elf_Rela &b) {
-    return a.r_offset < b.r_offset;
-  });
-  if (!nonRelatives.empty()) {
-    add(nonRelatives.size());
+  // Grouped non-relatives.
+  for (ArrayRef<Elf_Rela> g : nonRelativeGroups) {
+    add(g.size());
+    add(RELOCATION_GROUPED_BY_INFO_FLAG);
+    add(g[0].r_info);
+    for (const Elf_Rela &r : g) {
+      add(r.r_offset - offset);
+      offset = r.r_offset;
+    }
+    addend = 0;
+  }
+
+  // Finally the ungrouped non-relative relocations.
+  if (!ungroupedNonRelatives.empty()) {
+    add(ungroupedNonRelatives.size());
     add(hasAddendIfRela);
-    for (Elf_Rela &r : nonRelatives) {
+    for (Elf_Rela &r : ungroupedNonRelatives) {
       add(r.r_offset - offset);
       offset = r.r_offset;
       add(r.r_info);

Modified: lld/trunk/test/ELF/pack-dyn-relocs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/pack-dyn-relocs.s?rev=369507&r1=369506&r2=369507&view=diff
==============================================================================
--- lld/trunk/test/ELF/pack-dyn-relocs.s (original)
+++ lld/trunk/test/ELF/pack-dyn-relocs.s Wed Aug 21 02:21:37 2019
@@ -2,8 +2,8 @@
 
 // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %p/Inputs/arm-shared.s -o %t.a32.so.o
 // RUN: ld.lld -shared %t.a32.so.o -soname=so -o %t.a32.so
-// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.a32
-// RUN: ld.lld -pie --pack-dyn-relocs=none %t.a32 %t.a32.so -o %t2.a32
+// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.a32.o
+// RUN: ld.lld -pie --pack-dyn-relocs=none %t.a32.o %t.a32.so -o %t2.a32
 // RUN: llvm-readobj -r %t2.a32 | FileCheck --check-prefix=UNPACKED32 %s
 
 // Unpacked should have the relative relocations in their natural order.
@@ -25,7 +25,6 @@
 // UNPACKED32-NEXT:     0x2038 R_ARM_RELATIVE - 0x0
 // UNPACKED32-NEXT:     0x203C R_ARM_RELATIVE - 0x0
 
-// UNPACKED32-NEXT:     0x2044 R_ARM_RELATIVE - 0x0
 // UNPACKED32-NEXT:     0x2048 R_ARM_RELATIVE - 0x0
 // UNPACKED32-NEXT:     0x204C R_ARM_RELATIVE - 0x0
 // UNPACKED32-NEXT:     0x2050 R_ARM_RELATIVE - 0x0
@@ -34,13 +33,20 @@
 // UNPACKED32-NEXT:     0x205C R_ARM_RELATIVE - 0x0
 // UNPACKED32-NEXT:     0x2060 R_ARM_RELATIVE - 0x0
 // UNPACKED32-NEXT:     0x2064 R_ARM_RELATIVE - 0x0
+// UNPACKED32-NEXT:     0x2068 R_ARM_RELATIVE - 0x0
 
-// UNPACKED32-NEXT:     0x2069 R_ARM_RELATIVE - 0x0
+// UNPACKED32-NEXT:     0x206D R_ARM_RELATIVE - 0x0
 // UNPACKED32-NEXT:     0x2020 R_ARM_ABS32 bar2 0x0
+// UNPACKED32-NEXT:     0x2044 R_ARM_ABS32 bar2 0x0
+// UNPACKED32-NEXT:     0x2071 R_ARM_ABS32 bar2 0x0
+// UNPACKED32-NEXT:     0x2075 R_ARM_ABS32 bar2 0x0
+// UNPACKED32-NEXT:     0x2079 R_ARM_ABS32 bar2 0x0
+// UNPACKED32-NEXT:     0x207D R_ARM_ABS32 bar2 0x0
+// UNPACKED32-NEXT:     0x2081 R_ARM_ABS32 bar2 0x0
 // UNPACKED32-NEXT:     0x2040 R_ARM_ABS32 zed2 0x0
 // UNPACKED32-NEXT:     }
 
-// RUN: ld.lld -pie --pack-dyn-relocs=android %t.a32 %t.a32.so -o %t3.a32
+// RUN: ld.lld -pie --pack-dyn-relocs=android %t.a32.o %t.a32.so -o %t3.a32
 // RUN: llvm-readobj -S --dynamic-table %t3.a32 | FileCheck --check-prefix=ANDROID32-HEADERS %s
 // RUN: llvm-readobj -r %t3.a32 | FileCheck --check-prefix=ANDROID32 %s
 
@@ -63,8 +69,9 @@
 // ANDROID32-HEADERS: 0x6000000F ANDROID_REL          [[ADDR]]
 // ANDROID32-HEADERS: 0x60000010 ANDROID_RELSZ        [[SIZE]]
 
-// Packed should have the larger groups of relative relocations first,
-// i.e. the 8 and 9 followed by the 7.
+// Packed should have the groups of non-relative reloations first, followed
+// by the larger groups of relative relocations (i.e. the 8 and 9 followed
+// by the 7.)
 // ANDROID32:          Section ({{.+}}) .rel.dyn {
 // ANDROID32-NEXT:     0x2000 R_ARM_RELATIVE - 0x0
 // ANDROID32-NEXT:     0x2004 R_ARM_RELATIVE - 0x0
@@ -75,7 +82,6 @@
 // ANDROID32-NEXT:     0x2018 R_ARM_RELATIVE - 0x0
 // ANDROID32-NEXT:     0x201C R_ARM_RELATIVE - 0x0
 
-// ANDROID32-NEXT:     0x2044 R_ARM_RELATIVE - 0x0
 // ANDROID32-NEXT:     0x2048 R_ARM_RELATIVE - 0x0
 // ANDROID32-NEXT:     0x204C R_ARM_RELATIVE - 0x0
 // ANDROID32-NEXT:     0x2050 R_ARM_RELATIVE - 0x0
@@ -84,6 +90,7 @@
 // ANDROID32-NEXT:     0x205C R_ARM_RELATIVE - 0x0
 // ANDROID32-NEXT:     0x2060 R_ARM_RELATIVE - 0x0
 // ANDROID32-NEXT:     0x2064 R_ARM_RELATIVE - 0x0
+// ANDROID32-NEXT:     0x2068 R_ARM_RELATIVE - 0x0
 
 // ANDROID32-NEXT:     0x2024 R_ARM_RELATIVE - 0x0
 // ANDROID32-NEXT:     0x2028 R_ARM_RELATIVE - 0x0
@@ -93,12 +100,20 @@
 // ANDROID32-NEXT:     0x2038 R_ARM_RELATIVE - 0x0
 // ANDROID32-NEXT:     0x203C R_ARM_RELATIVE - 0x0
 
-// ANDROID32-NEXT:     0x2069 R_ARM_RELATIVE - 0x0
+// ANDROID32-NEXT:     0x206D R_ARM_RELATIVE - 0x0
+
 // ANDROID32-NEXT:     0x2020 R_ARM_ABS32 bar2 0x0
+// ANDROID32-NEXT:     0x2044 R_ARM_ABS32 bar2 0x0
+// ANDROID32-NEXT:     0x2071 R_ARM_ABS32 bar2 0x0
+// ANDROID32-NEXT:     0x2075 R_ARM_ABS32 bar2 0x0
+// ANDROID32-NEXT:     0x2079 R_ARM_ABS32 bar2 0x0
+// ANDROID32-NEXT:     0x207D R_ARM_ABS32 bar2 0x0
+// ANDROID32-NEXT:     0x2081 R_ARM_ABS32 bar2 0x0
+
 // ANDROID32-NEXT:     0x2040 R_ARM_ABS32 zed2 0x0
 // ANDROID32-NEXT:     }
 
-// RUN: ld.lld -pie --pack-dyn-relocs=relr %t.a32 %t.a32.so -o %t4.a32
+// RUN: ld.lld -pie --pack-dyn-relocs=relr %t.a32.o %t.a32.so -o %t4.a32
 // RUN: llvm-readobj -S --dynamic-table %t4.a32 | FileCheck --check-prefix=RELR32-HEADERS %s
 // RUN: llvm-readobj -r --raw-relr %t4.a32 | FileCheck --check-prefix=RAW-RELR32 %s
 // RUN: llvm-readobj -r %t4.a32 | FileCheck --check-prefix=RELR32 %s
@@ -127,15 +142,21 @@
 // encoding the offsets for relative relocation.
 // RAW-RELR32:           Section ({{.+}}) .relr.dyn {
 // RAW-RELR32-NEXT:      0x2000
-// RAW-RELR32-NEXT:      0x3FEFEFF
+// RAW-RELR32-NEXT:      0x7FCFEFF
 // RAW-RELR32-NEXT:      }
 
 // Decoded SHT_RELR section is same as UNPACKED,
 // but contains only the relative relocations.
 // Any relative relocations with odd offset stay in SHT_REL.
 // RELR32:               Section ({{.+}}) .rel.dyn {
-// RELR32-NEXT:          0x2069 R_ARM_RELATIVE - 0x0
+// RELR32-NEXT:          0x206D R_ARM_RELATIVE - 0x0
 // RELR32-NEXT:          0x2020 R_ARM_ABS32 bar2 0x0
+// RELR32-NEXT:          0x2044 R_ARM_ABS32 bar2 0x0
+// RELR32-NEXT:          0x2071 R_ARM_ABS32 bar2 0x0
+// RELR32-NEXT:          0x2075 R_ARM_ABS32 bar2 0x0
+// RELR32-NEXT:          0x2079 R_ARM_ABS32 bar2 0x0
+// RELR32-NEXT:          0x207D R_ARM_ABS32 bar2 0x0
+// RELR32-NEXT:          0x2081 R_ARM_ABS32 bar2 0x0
 // RELR32-NEXT:          0x2040 R_ARM_ABS32 zed2 0x0
 // RELR32-NEXT:          }
 // RELR32-NEXT:          Section ({{.+}}) .relr.dyn {
@@ -156,7 +177,6 @@
 // RELR32-NEXT:          0x2038 R_ARM_RELATIVE - 0x0
 // RELR32-NEXT:          0x203C R_ARM_RELATIVE - 0x0
 
-// RELR32-NEXT:          0x2044 R_ARM_RELATIVE - 0x0
 // RELR32-NEXT:          0x2048 R_ARM_RELATIVE - 0x0
 // RELR32-NEXT:          0x204C R_ARM_RELATIVE - 0x0
 // RELR32-NEXT:          0x2050 R_ARM_RELATIVE - 0x0
@@ -165,48 +185,55 @@
 // RELR32-NEXT:          0x205C R_ARM_RELATIVE - 0x0
 // RELR32-NEXT:          0x2060 R_ARM_RELATIVE - 0x0
 // RELR32-NEXT:          0x2064 R_ARM_RELATIVE - 0x0
+// RELR32-NEXT:          0x2068 R_ARM_RELATIVE - 0x0
 // RELR32-NEXT:          }
 
 // RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-linux %p/Inputs/shared2.s -o %t.a64.so.o
 // RUN: ld.lld -shared %t.a64.so.o -soname=so -o %t.a64.so
-// RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-linux %s -o %t.a64
-// RUN: ld.lld -pie --pack-dyn-relocs=none %t.a64 %t.a64.so -o %t2.a64
+// RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-linux %s -o %t.a64.o
+// RUN: ld.lld -pie --pack-dyn-relocs=none %t.a64.o %t.a64.so -o %t2.a64
 // RUN: llvm-readobj -r %t2.a64 | FileCheck --check-prefix=UNPACKED64 %s
 
 // UNPACKED64:          Section ({{.+}}) .rela.dyn {
-// UNPACKED64-NEXT:     0x305F0 R_AARCH64_RELATIVE - 0x1
-// UNPACKED64-NEXT:     0x305F8 R_AARCH64_RELATIVE - 0x2
-// UNPACKED64-NEXT:     0x30600 R_AARCH64_RELATIVE - 0x3
-// UNPACKED64-NEXT:     0x30608 R_AARCH64_RELATIVE - 0x4
-// UNPACKED64-NEXT:     0x30610 R_AARCH64_RELATIVE - 0x5
-// UNPACKED64-NEXT:     0x30618 R_AARCH64_RELATIVE - 0x6
-// UNPACKED64-NEXT:     0x30620 R_AARCH64_RELATIVE - 0x7
-// UNPACKED64-NEXT:     0x30628 R_AARCH64_RELATIVE - 0x8
-
-// UNPACKED64-NEXT:     0x30638 R_AARCH64_RELATIVE - 0x1
-// UNPACKED64-NEXT:     0x30640 R_AARCH64_RELATIVE - 0x2
-// UNPACKED64-NEXT:     0x30648 R_AARCH64_RELATIVE - 0x3
-// UNPACKED64-NEXT:     0x30650 R_AARCH64_RELATIVE - 0x4
-// UNPACKED64-NEXT:     0x30658 R_AARCH64_RELATIVE - 0x5
-// UNPACKED64-NEXT:     0x30660 R_AARCH64_RELATIVE - 0x6
-// UNPACKED64-NEXT:     0x30668 R_AARCH64_RELATIVE - 0x7
-
-// UNPACKED64-NEXT:     0x30678 R_AARCH64_RELATIVE - 0x1
-// UNPACKED64-NEXT:     0x30680 R_AARCH64_RELATIVE - 0x2
-// UNPACKED64-NEXT:     0x30688 R_AARCH64_RELATIVE - 0x3
-// UNPACKED64-NEXT:     0x30690 R_AARCH64_RELATIVE - 0x4
-// UNPACKED64-NEXT:     0x30698 R_AARCH64_RELATIVE - 0x5
-// UNPACKED64-NEXT:     0x306A0 R_AARCH64_RELATIVE - 0x6
-// UNPACKED64-NEXT:     0x306A8 R_AARCH64_RELATIVE - 0x7
-// UNPACKED64-NEXT:     0x306B0 R_AARCH64_RELATIVE - 0x8
-// UNPACKED64-NEXT:     0x306B8 R_AARCH64_RELATIVE - 0x9
-
-// UNPACKED64-NEXT:     0x306C1 R_AARCH64_RELATIVE - 0xA
-// UNPACKED64-NEXT:     0x30630 R_AARCH64_ABS64 bar2 0x1
-// UNPACKED64-NEXT:     0x30670 R_AARCH64_ABS64 zed2 0x0
+// UNPACKED64-NEXT:     0x30680 R_AARCH64_RELATIVE - 0x1
+// UNPACKED64-NEXT:     0x30688 R_AARCH64_RELATIVE - 0x2
+// UNPACKED64-NEXT:     0x30690 R_AARCH64_RELATIVE - 0x3
+// UNPACKED64-NEXT:     0x30698 R_AARCH64_RELATIVE - 0x4
+// UNPACKED64-NEXT:     0x306A0 R_AARCH64_RELATIVE - 0x5
+// UNPACKED64-NEXT:     0x306A8 R_AARCH64_RELATIVE - 0x6
+// UNPACKED64-NEXT:     0x306B0 R_AARCH64_RELATIVE - 0x7
+// UNPACKED64-NEXT:     0x306B8 R_AARCH64_RELATIVE - 0x8
+
+// UNPACKED64-NEXT:     0x306C8 R_AARCH64_RELATIVE - 0x1
+// UNPACKED64-NEXT:     0x306D0 R_AARCH64_RELATIVE - 0x2
+// UNPACKED64-NEXT:     0x306D8 R_AARCH64_RELATIVE - 0x3
+// UNPACKED64-NEXT:     0x306E0 R_AARCH64_RELATIVE - 0x4
+// UNPACKED64-NEXT:     0x306E8 R_AARCH64_RELATIVE - 0x5
+// UNPACKED64-NEXT:     0x306F0 R_AARCH64_RELATIVE - 0x6
+// UNPACKED64-NEXT:     0x306F8 R_AARCH64_RELATIVE - 0x7
+
+// UNPACKED64-NEXT:     0x30710 R_AARCH64_RELATIVE - 0x1
+// UNPACKED64-NEXT:     0x30718 R_AARCH64_RELATIVE - 0x2
+// UNPACKED64-NEXT:     0x30720 R_AARCH64_RELATIVE - 0x3
+// UNPACKED64-NEXT:     0x30728 R_AARCH64_RELATIVE - 0x4
+// UNPACKED64-NEXT:     0x30730 R_AARCH64_RELATIVE - 0x5
+// UNPACKED64-NEXT:     0x30738 R_AARCH64_RELATIVE - 0x6
+// UNPACKED64-NEXT:     0x30740 R_AARCH64_RELATIVE - 0x7
+// UNPACKED64-NEXT:     0x30748 R_AARCH64_RELATIVE - 0x8
+// UNPACKED64-NEXT:     0x30750 R_AARCH64_RELATIVE - 0x9
+
+// UNPACKED64-NEXT:     0x30759 R_AARCH64_RELATIVE - 0xA
+// UNPACKED64-NEXT:     0x306C0 R_AARCH64_ABS64 bar2 0x1
+// UNPACKED64-NEXT:     0x30708 R_AARCH64_ABS64 bar2 0x0
+// UNPACKED64-NEXT:     0x30761 R_AARCH64_ABS64 bar2 0x0
+// UNPACKED64-NEXT:     0x30769 R_AARCH64_ABS64 bar2 0x0
+// UNPACKED64-NEXT:     0x30771 R_AARCH64_ABS64 bar2 0x1
+// UNPACKED64-NEXT:     0x30779 R_AARCH64_ABS64 bar2 0x1
+// UNPACKED64-NEXT:     0x30781 R_AARCH64_ABS64 bar2 0x0
+// UNPACKED64-NEXT:     0x30700 R_AARCH64_ABS64 zed2 0x0
 // UNPACKED64-NEXT:     }
 
-// RUN: ld.lld -pie --pack-dyn-relocs=android %t.a64 %t.a64.so -o %t3.a64
+// RUN: ld.lld -pie --pack-dyn-relocs=android %t.a64.o %t.a64.so -o %t3.a64
 // RUN: llvm-readobj -S --dynamic-table %t3.a64 | FileCheck --check-prefix=ANDROID64-HEADERS %s
 // RUN: llvm-readobj -r %t3.a64 | FileCheck --check-prefix=ANDROID64 %s
 
@@ -230,39 +257,45 @@
 // ANDROID64-HEADERS: 0x0000000060000012 ANDROID_RELASZ        [[SIZE]]
 
 // ANDROID64:          Section ({{.+}}) .rela.dyn {
-// ANDROID64-NEXT:     0x303C0 R_AARCH64_RELATIVE - 0x1
-// ANDROID64-NEXT:     0x303C8 R_AARCH64_RELATIVE - 0x2
-// ANDROID64-NEXT:     0x303D0 R_AARCH64_RELATIVE - 0x3
-// ANDROID64-NEXT:     0x303D8 R_AARCH64_RELATIVE - 0x4
-// ANDROID64-NEXT:     0x303E0 R_AARCH64_RELATIVE - 0x5
-// ANDROID64-NEXT:     0x303E8 R_AARCH64_RELATIVE - 0x6
-// ANDROID64-NEXT:     0x303F0 R_AARCH64_RELATIVE - 0x7
-// ANDROID64-NEXT:     0x303F8 R_AARCH64_RELATIVE - 0x8
-
-// ANDROID64-NEXT:     0x30448 R_AARCH64_RELATIVE - 0x1
-// ANDROID64-NEXT:     0x30450 R_AARCH64_RELATIVE - 0x2
-// ANDROID64-NEXT:     0x30458 R_AARCH64_RELATIVE - 0x3
-// ANDROID64-NEXT:     0x30460 R_AARCH64_RELATIVE - 0x4
-// ANDROID64-NEXT:     0x30468 R_AARCH64_RELATIVE - 0x5
-// ANDROID64-NEXT:     0x30470 R_AARCH64_RELATIVE - 0x6
-// ANDROID64-NEXT:     0x30478 R_AARCH64_RELATIVE - 0x7
-// ANDROID64-NEXT:     0x30480 R_AARCH64_RELATIVE - 0x8
-// ANDROID64-NEXT:     0x30488 R_AARCH64_RELATIVE - 0x9
-
-// ANDROID64-NEXT:     0x30408 R_AARCH64_RELATIVE - 0x1
-// ANDROID64-NEXT:     0x30410 R_AARCH64_RELATIVE - 0x2
-// ANDROID64-NEXT:     0x30418 R_AARCH64_RELATIVE - 0x3
-// ANDROID64-NEXT:     0x30420 R_AARCH64_RELATIVE - 0x4
-// ANDROID64-NEXT:     0x30428 R_AARCH64_RELATIVE - 0x5
-// ANDROID64-NEXT:     0x30430 R_AARCH64_RELATIVE - 0x6
-// ANDROID64-NEXT:     0x30438 R_AARCH64_RELATIVE - 0x7
-
-// ANDROID64-NEXT:     0x30491 R_AARCH64_RELATIVE - 0xA
-// ANDROID64-NEXT:     0x30400 R_AARCH64_ABS64 bar2 0x1
-// ANDROID64-NEXT:     0x30440 R_AARCH64_ABS64 zed2 0x0
+// ANDROID64-NEXT:     0x303E0 R_AARCH64_RELATIVE - 0x1
+// ANDROID64-NEXT:     0x303E8 R_AARCH64_RELATIVE - 0x2
+// ANDROID64-NEXT:     0x303F0 R_AARCH64_RELATIVE - 0x3
+// ANDROID64-NEXT:     0x303F8 R_AARCH64_RELATIVE - 0x4
+// ANDROID64-NEXT:     0x30400 R_AARCH64_RELATIVE - 0x5
+// ANDROID64-NEXT:     0x30408 R_AARCH64_RELATIVE - 0x6
+// ANDROID64-NEXT:     0x30410 R_AARCH64_RELATIVE - 0x7
+// ANDROID64-NEXT:     0x30418 R_AARCH64_RELATIVE - 0x8
+
+// ANDROID64-NEXT:     0x30470 R_AARCH64_RELATIVE - 0x1
+// ANDROID64-NEXT:     0x30478 R_AARCH64_RELATIVE - 0x2
+// ANDROID64-NEXT:     0x30480 R_AARCH64_RELATIVE - 0x3
+// ANDROID64-NEXT:     0x30488 R_AARCH64_RELATIVE - 0x4
+// ANDROID64-NEXT:     0x30490 R_AARCH64_RELATIVE - 0x5
+// ANDROID64-NEXT:     0x30498 R_AARCH64_RELATIVE - 0x6
+// ANDROID64-NEXT:     0x304A0 R_AARCH64_RELATIVE - 0x7
+// ANDROID64-NEXT:     0x304A8 R_AARCH64_RELATIVE - 0x8
+// ANDROID64-NEXT:     0x304B0 R_AARCH64_RELATIVE - 0x9
+
+// ANDROID64-NEXT:     0x30428 R_AARCH64_RELATIVE - 0x1
+// ANDROID64-NEXT:     0x30430 R_AARCH64_RELATIVE - 0x2
+// ANDROID64-NEXT:     0x30438 R_AARCH64_RELATIVE - 0x3
+// ANDROID64-NEXT:     0x30440 R_AARCH64_RELATIVE - 0x4
+// ANDROID64-NEXT:     0x30448 R_AARCH64_RELATIVE - 0x5
+// ANDROID64-NEXT:     0x30450 R_AARCH64_RELATIVE - 0x6
+// ANDROID64-NEXT:     0x30458 R_AARCH64_RELATIVE - 0x7
+// ANDROID64-NEXT:     0x304B9 R_AARCH64_RELATIVE - 0xA
+
+// ANDROID64-NEXT:     0x30468 R_AARCH64_ABS64 bar2 0x0
+// ANDROID64-NEXT:     0x304C1 R_AARCH64_ABS64 bar2 0x0
+// ANDROID64-NEXT:     0x304C9 R_AARCH64_ABS64 bar2 0x0
+// ANDROID64-NEXT:     0x304E1 R_AARCH64_ABS64 bar2 0x0
+// ANDROID64-NEXT:     0x30420 R_AARCH64_ABS64 bar2 0x1
+// ANDROID64-NEXT:     0x30460 R_AARCH64_ABS64 zed2 0x0
+// ANDROID64-NEXT:     0x304D1 R_AARCH64_ABS64 bar2 0x1
+// ANDROID64-NEXT:     0x304D9 R_AARCH64_ABS64 bar2 0x1
 // ANDROID64-NEXT:     }
 
-// RUN: ld.lld -pie --pack-dyn-relocs=relr %t.a64 %t.a64.so -o %t4.a64
+// RUN: ld.lld -pie --pack-dyn-relocs=relr %t.a64.o %t.a64.so -o %t4.a64
 // RUN: llvm-readobj -S --dynamic-table %t4.a64 | FileCheck --check-prefix=RELR64-HEADERS %s
 // RUN: llvm-readobj -r --raw-relr %t4.a64 | FileCheck --check-prefix=RAW-RELR64 %s
 // RUN: llvm-readobj -r %t4.a64 | FileCheck --check-prefix=RELR64 %s
@@ -290,46 +323,50 @@
 // SHT_RELR section contains address/bitmap entries
 // encoding the offsets for relative relocation.
 // RAW-RELR64:           Section ({{.+}}) .relr.dyn {
-// RAW-RELR64-NEXT:      0x303F0
-// RAW-RELR64-NEXT:      0x3FEFEFF
+// RAW-RELR64-NEXT:      0x30480
+// RAW-RELR64-NEXT:      0x7FCFEFF
 // RAW-RELR64-NEXT:      }
 
 // Decoded SHT_RELR section is same as UNPACKED,
 // but contains only the relative relocations.
 // Any relative relocations with odd offset stay in SHT_RELA.
-// RELR64:               Section ({{.+}}) .rela.dyn {
-// RELR64-NEXT:          0x304C1 R_AARCH64_RELATIVE - 0xA
-// RELR64-NEXT:          0x30430 R_AARCH64_ABS64 bar2 0x1
-// RELR64-NEXT:          0x30470 R_AARCH64_ABS64 zed2 0x0
-// RELR64-NEXT:          }
-// RELR64-NEXT:          Section ({{.+}}) .relr.dyn {
-// RELR64-NEXT:          0x303F0 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x303F8 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x30400 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x30408 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x30410 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x30418 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x30420 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x30428 R_AARCH64_RELATIVE - 0x0
-
-// RELR64-NEXT:          0x30438 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x30440 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x30448 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x30450 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x30458 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x30460 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x30468 R_AARCH64_RELATIVE - 0x0
-
-// RELR64-NEXT:          0x30478 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x30480 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x30488 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x30490 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x30498 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x304A0 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x304A8 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x304B0 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          0x304B8 R_AARCH64_RELATIVE - 0x0
-// RELR64-NEXT:          }
+// RELR64:      Section ({{.+}}) .rela.dyn {
+// RELR64-NEXT:   0x30559 R_AARCH64_RELATIVE - 0xA
+// RELR64-NEXT:   0x304C0 R_AARCH64_ABS64 bar2 0x1
+// RELR64-NEXT:   0x30508 R_AARCH64_ABS64 bar2 0x0
+// RELR64-NEXT:   0x30561 R_AARCH64_ABS64 bar2 0x0
+// RELR64-NEXT:   0x30569 R_AARCH64_ABS64 bar2 0x0
+// RELR64-NEXT:   0x30571 R_AARCH64_ABS64 bar2 0x1
+// RELR64-NEXT:   0x30579 R_AARCH64_ABS64 bar2 0x1
+// RELR64-NEXT:   0x30581 R_AARCH64_ABS64 bar2 0x0
+// RELR64-NEXT:   0x30500 R_AARCH64_ABS64 zed2 0x0
+// RELR64-NEXT: }
+// RELR64-NEXT: Section ({{.+}}) .relr.dyn {
+// RELR64-NEXT:   0x30480 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x30488 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x30490 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x30498 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x304A0 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x304A8 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x304B0 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x304B8 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x304C8 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x304D0 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x304D8 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x304E0 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x304E8 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x304F0 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x304F8 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x30510 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x30518 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x30520 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x30528 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x30530 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x30538 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x30540 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x30548 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT:   0x30550 R_AARCH64_RELATIVE - 0x0
+// RELR64-NEXT: }
 
 .data
 .align 2
@@ -351,6 +388,7 @@
 .dc.a __ehdr_start + 6
 .dc.a __ehdr_start + 7
 .dc.a zed2
+.dc.a bar2
 
 .dc.a __ehdr_start + 1
 .dc.a __ehdr_start + 2
@@ -363,3 +401,8 @@
 .dc.a __ehdr_start + 9
 .byte 00
 .dc.a __ehdr_start + 10
+.dc.a bar2
+.dc.a bar2
+.dc.a bar2 + 1
+.dc.a bar2 + 1
+.dc.a bar2




More information about the llvm-commits mailing list