[PATCH] D47602: Correct aligment computation for shared object symbols

Han Shen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 31 15:43:48 PDT 2018


shenhan updated this revision to Diff 149374.

Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D47602

Files:
  ELF/InputFiles.cpp
  test/ELF/Inputs/relocation-copy-alignment.s
  test/ELF/relocation-copy-alignment.s


Index: test/ELF/relocation-copy-alignment.s
===================================================================
--- /dev/null
+++ test/ELF/relocation-copy-alignment.s
@@ -0,0 +1,28 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/relocation-copy-alignment.s -o %t2.o
+// RUN: ld.lld -shared %t2.o -o %t.so
+// RUN: ld.lld %t.o %t.so -o %t3
+// RUN: llvm-readobj -s -r --expand-relocs %t3 | FileCheck %s
+
+.text
+.global _start
+_start:
+movl $5, dso_symbol
+movl $6, dso_symbol1
+
+// Symbol alignment information must be kept.
+// CHECK:       Section (5) .rela.dyn {
+// CHECK-NEXT:    Relocation {
+// CHECK-NEXT:      Offset: 0x203000
+// CHECK-NEXT:      Type: R_X86_64_COPY
+// CHECK-NEXT:      Symbol: dso_symbol
+// CHECK-NEXT:      Addend: 0
+// CHECK-NEXT:    }
+// CHECK-NEXT:    Relocation {
+// CHECK-NEXT:      Offset: 0x203010
+// CHECK-NEXT:      Type: R_X86_64_COPY
+// CHECK-NEXT:      Symbol: dso_symbol1
+// CHECK-NEXT:      Addend: 0
+// CHECK-NEXT:    }
+// CHECK-NEXT:  }
Index: test/ELF/Inputs/relocation-copy-alignment.s
===================================================================
--- /dev/null
+++ test/ELF/Inputs/relocation-copy-alignment.s
@@ -0,0 +1,7 @@
+.data
+.type	dso_symbol, at object
+.comm	dso_symbol,4,4
+
+.type	dso_symbol1, at object
+.comm	dso_symbol1,16,16
+
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -895,7 +895,11 @@
 template <class ELFT>
 uint32_t SharedFile<ELFT>::getAlignment(ArrayRef<Elf_Shdr> Sections,
                                         const Elf_Sym &Sym) {
-  uint64_t Ret = 1;
+  // If no available alignment information from either section or
+  // symbol, return 1.
+  if (!(Sym.st_value || (0 < Sym.st_shndx && Sym.st_shndx < Sections.size())))
+    return 1;
+  uint64_t Ret = UINT64_MAX;
   if (Sym.st_value)
     Ret = 1ULL << countTrailingZeros((uint64_t)Sym.st_value);
   if (0 < Sym.st_shndx && Sym.st_shndx < Sections.size())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47602.149374.patch
Type: text/x-patch
Size: 2104 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180531/74705656/attachment.bin>


More information about the llvm-commits mailing list