Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -895,7 +895,11 @@ template uint32_t SharedFile::getAlignment(ArrayRef 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()) 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,@object +.comm dso_symbol,4,4 + +.type dso_symbol1,@object +.comm dso_symbol1,16,16 + 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: }