Index: lld/trunk/ELF/InputFiles.cpp =================================================================== --- lld/trunk/ELF/InputFiles.cpp +++ lld/trunk/ELF/InputFiles.cpp @@ -900,16 +900,12 @@ template uint32_t SharedFile::getAlignment(ArrayRef Sections, const Elf_Sym &Sym) { - uint64_t Ret = 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()) Ret = std::min(Ret, Sections[Sym.st_shndx].sh_addralign); - - if (Ret > UINT32_MAX) - error(toString(this) + ": alignment too large: " + - CHECK(Sym.getName(this->StringTable), this)); - return Ret; + return (Ret > UINT32_MAX) ? 0 : Ret; } // Fully parse the shared object file. This must be called after parseSoName(). Index: lld/trunk/ELF/Relocations.cpp =================================================================== --- lld/trunk/ELF/Relocations.cpp +++ lld/trunk/ELF/Relocations.cpp @@ -528,7 +528,7 @@ template static void addCopyRelSymbol(SharedSymbol &SS) { // Copy relocation against zero-sized symbol doesn't make sense. uint64_t SymSize = SS.getSize(); - if (SymSize == 0) + if (SymSize == 0 || SS.Alignment == 0) fatal("cannot create a copy relocation for symbol " + toString(SS)); // See if this symbol is in a read-only segment. If so, preserve the symbol's Index: lld/trunk/test/ELF/Inputs/copy-relocation-zero-abs-addr.s =================================================================== --- lld/trunk/test/ELF/Inputs/copy-relocation-zero-abs-addr.s +++ lld/trunk/test/ELF/Inputs/copy-relocation-zero-abs-addr.s @@ -0,0 +1,7 @@ +.globl ver1 +.globl ver2 + ver1 = 0x0 + ver2 = 0x0 + +.type foo,@object +.comm foo,16,16 Index: lld/trunk/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.s =================================================================== --- lld/trunk/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.s +++ lld/trunk/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.s @@ -0,0 +1,7 @@ +.balign 1024 +.type foo,@object +.globl foo +goo: +foo: + .long 0 + .size foo,4 Index: lld/trunk/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.script =================================================================== --- lld/trunk/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.script +++ lld/trunk/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.script @@ -0,0 +1,3 @@ +SECTIONS { + goo = 0; +}; Index: lld/trunk/test/ELF/copy-relocation-zero-abs-addr.s =================================================================== --- lld/trunk/test/ELF/copy-relocation-zero-abs-addr.s +++ lld/trunk/test/ELF/copy-relocation-zero-abs-addr.s @@ -0,0 +1,44 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/copy-relocation-zero-abs-addr.s -o %t.o +// RUN: ld.lld -shared -o %t2.so %t.o +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t3.o +// RUN: ld.lld %t2.so %t3.o -o %t4 +// RUN: llvm-readobj -symbols %t2.so | FileCheck -check-prefix=ABSADDR %s +// RUN: llvm-readobj -s -r --expand-relocs %t4 | FileCheck %s + +// This tests that symbols with absolute addresses are properly +// handled. Normal DSO symbols are handled as usual. + +.text +.globl _start +_start: + movl $5, foo + +// ABSADDR: Name: ver1 +// ABSADDR-NEXT: Value: 0x0 +// ABSADDR-NEXT: Size: 0 +// ABSADDR-NEXT: Binding: Global +// ABSADDR-NEXT: Type: None +// ABSADDR-NEXT: Other: 0 +// ABSADDR-NEXT: Section: Absolute (0xFFF1) +// ABSADDR-NEXT: } +// ABSADDR-NEXT: Symbol { +// ABSADDR-NEXT: Name: ver2 +// ABSADDR-NEXT: Value: 0x0 +// ABSADDR-NEXT: Size: 0 +// ABSADDR-NEXT: Binding: Global +// ABSADDR-NEXT: Type: None +// ABSADDR-NEXT: Other: 0 +// ABSADDR-NEXT: Section: Absolute (0xFFF1) +// ABSADDR-NEXT: } + +// CHECK: Relocations [ +// CHECK-NEXT: Section (5) .rela.dyn { +// CHECK-NEXT: Relocation { +// CHECK-NEXT: Offset: +// CHECK-NEXT: Type: R_X86_64_COPY +// CHECK-NEXT: Symbol: foo +// CHECK-NEXT: Addend: +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: ] Index: lld/trunk/test/ELF/copy-relocation-zero-nonabs-addr.s =================================================================== --- lld/trunk/test/ELF/copy-relocation-zero-nonabs-addr.s +++ lld/trunk/test/ELF/copy-relocation-zero-nonabs-addr.s @@ -0,0 +1,29 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/copy-relocation-zero-nonabs-addr.s -o %t1.o +// RUN: ld.lld -Ttext=0 -o %t2.so --script=%p/Inputs/copy-relocation-zero-nonabs-addr.script %t1.o -shared +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t3.o +// RUN: ld.lld %t2.so %t3.o -o %t4 +// RUN: llvm-readobj --symbols %t2.so | FileCheck --check-prefix=CHECKSO %s +// RUN: llvm-readobj --symbols %t4 | FileCheck %s + +.text +.globl _start +_start: + movl $5, foo + +// Make sure foo has st_value == 0. +// CHECKSO: Name: foo +// CHECKSO-NEXT: Value: 0x0 +// CHECKSO-NEXT: Size: 4 +// CHECKSO-NEXT: Binding: Global +// CHECKSO-NEXT: Type: Object +// CHECKSO-NEXT: Other: 0 +// CHECKSO-NEXT: Section: .text + +// When foo has st_value == 0, it carries the section alignment. +// In this case, section alignment is 2^10, 0x202400 meets the requirement. +// CHECK: Name: foo +// CHECK-NEXT: Value: 0x202400 +// CHECK-NEXT: Size: 4 +// CHECK-NEXT: Binding: Global +// CHECK-NEXT: Type: Object