Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Mar 22, 2021
1 parent a1d8b56 commit f56215a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
11 changes: 0 additions & 11 deletions input_sections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions test/reloc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f56215a

Please sign in to comment.