diff --git a/input_sections.cc b/input_sections.cc index 283ba3f1..63fa0bbc 100644 --- a/input_sections.cc +++ b/input_sections.cc @@ -458,17 +458,6 @@ void InputSection::apply_reloc_nonalloc(u8 *base) { write_val(rel.r_type, loc, val); }; - // Debug info section may have relocations pointing to - // non-alloc sections. Such relocations are not valid. - // We treat them as if they were pointing to address 0. - bool is_valid = (!sym.input_section || - (sym.input_section->shdr.sh_flags & SHF_ALLOC)); - - if (!is_valid) { - write(0); - continue; - } - switch (rel.r_type) { case R_X86_64_NONE: break; diff --git a/test/reloc.sh b/test/reloc.sh index aa38c87a..4215916f 100755 --- a/test/reloc.sh +++ b/test/reloc.sh @@ -174,4 +174,28 @@ clang -c -o $t/e.o $t/e.c -mcmodel=large -fPIC clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.so $t/e.o $t/exe | grep -q 56 +# R_X86_64_32 against non-alloc section +cat <<'EOF' > $t/f.s +.globl main +main: + ret + +.section .foo, "", @progbits +.zero 16 +foo: +.quad bar + +.section .bar, "", @progbits +.zero 24 +bar: +.quad foo +EOF + +clang -c -o $t/f.o $t/f.s +clang -fuse-ld=`pwd`/../mold -o $t/exe $t/f.o +readelf -x .foo -x .bar $t/exe > $t/log + +fgrep -q '0x00000010 00000000 00000000 10000000 00000000' $t/log +fgrep -q '0x00000010 18000000 00000000' $t/log + echo OK