glibc/scripts/localplt.awk
Florian Weimer 77db67c56b scripts/localplt.awk: Handle DT_JMPREL with empty PLT (for C-SKY)
On csky-linux-gnuabiv2, binutils 2.33 produces a DT_JMPREL entry
for the dynamic loader if it does not contain any PLT relocations:

Dynamic section at offset 0x1df48 contains 19 entries:
  Tag        Type                         Name/Value
 0x0000000e (SONAME)                     Library soname: [ld-linux-cskyv2-hf.so.1]
 0x00000004 (HASH)                       0xd4
 0x6ffffef5 (GNU_HASH)                   0x1a8
 0x00000005 (STRTAB)                     0x4ac
 0x00000006 (SYMTAB)                     0x28c
 0x0000000a (STRSZ)                      527 (bytes)
 0x0000000b (SYMENT)                     16 (bytes)
 0x00000003 (PLTGOT)                     0x1f000
 0x00000002 (PLTRELSZ)                   0 (bytes)
 0x00000014 (PLTREL)                     RELA
 0x00000017 (JMPREL)                     0xaa4
 0x00000007 (RELA)                       0x75c
 0x00000008 (RELASZ)                     840 (bytes)
 0x00000009 (RELAENT)                    12 (bytes)
 0x6ffffffc (VERDEF)                     0x700
 0x6ffffffd (VERDEFNUM)                  3
 0x6ffffff0 (VERSYM)                     0x6bc
 0x6ffffff9 (RELACOUNT)                  68
 0x00000000 (NULL)                       0x0

This confuses the script:

Unexpected output from check-localplt: …/elf/ld.so.jmprel:
*** DT_JMPREL does not match any section's address

This commit changes the script to record the DT_PLTRELSZ value and
reject DT_JMPREL values not a section boundary only if DT_PLTRELSZ
is present with a non-zero value.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2022-10-27 11:36:44 +02:00

125 lines
3.3 KiB
Awk

# This awk script expects to get command-line files that are each
# the output of 'readelf -WSdr' on a single shared object, and named
# .../NAME.jmprel where NAME is the unadorned file name of the shared object.
# It writes "NAME: SYMBOL" for each PLT entry in NAME that refers to a
# symbol defined in the same object.
BEGIN {
result = 0;
pltrelsize = -1;
}
FILENAME != lastfile {
if (lastfile && jmprel_offset == 0 && rela_offset == 0 && rel_offset == 0) {
print FILENAME ": *** failed to find expected output (readelf -WSdr)";
result = 2;
}
if (pltrelsz > 0 && jmprel_offset == -1) {
print FILENAME ": Could not find section for DT_JMPREL";
result = 2;
}
lastfile = FILENAME;
jmprel_offset = 0;
rela_offset = 0;
rel_offset = 0;
pltrelsz = -1;
delete section_offset_by_address;
}
/^Section Headers:/ { in_shdrs = 1; next }
in_shdrs && !/^ +\[/ { in_shdrs = 0 }
in_shdrs && /^ +\[/ { sub(/\[ +/, "[") }
in_shdrs {
address = strtonum("0x" $4);
offset = strtonum("0x" $5);
section_offset_by_address[address] = offset;
}
in_shdrs { next }
$1 == "Offset" && $2 == "Info" { in_relocs = 1; next }
NF == 0 { in_relocs = 0 }
in_relocs && relocs_offset == jmprel_offset && NF >= 5 {
# Relocations against GNU_IFUNC symbols are not shown as an hexadecimal
# value, but rather as the resolver symbol followed by ().
if ($4 ~ /\(\)/) {
print whatfile, gensub(/@.*/, "", "g", $5)
} else {
symval = strtonum("0x" $4);
if (symval != 0)
print whatfile, gensub(/@.*/, "", "g", $5)
}
}
in_relocs && relocs_offset == rela_offset && NF >= 5 {
# Relocations against GNU_IFUNC symbols are not shown as an hexadecimal
# value, but rather as the resolver symbol followed by ().
if ($4 ~ /\(\)/) {
print whatfile, gensub(/@.*/, "", "g", $5), "RELA", $3
} else {
symval = strtonum("0x" $4);
if (symval != 0)
print whatfile, gensub(/@.*/, "", "g", $5), "RELA", $3
}
}
in_relocs && relocs_offset == rel_offset && NF >= 5 {
# Relocations against GNU_IFUNC symbols are not shown as an hexadecimal
# value, but rather as the resolver symbol followed by ().
if ($4 ~ /\(\)/) {
print whatfile, gensub(/@.*/, "", "g", $5), "REL", $3
} else {
symval = strtonum("0x" $4);
if (symval != 0)
print whatfile, gensub(/@.*/, "", "g", $5), "REL", $3
}
}
in_relocs { next }
$1 == "Relocation" && $2 == "section" && $5 == "offset" {
relocs_offset = strtonum($6);
whatfile = gensub(/^.*\/([^/]+)\.jmprel$/, "\\1:", 1, FILENAME);
next
}
$2 == "(JMPREL)" {
jmprel_addr = strtonum($3);
if (jmprel_addr in section_offset_by_address) {
jmprel_offset = section_offset_by_address[jmprel_addr];
} else {
jmprel_offset = -1
}
next
}
$2 == "(PLTRELSZ)" {
pltrelsz = strtonum($3);
next
}
$2 == "(RELA)" {
rela_addr = strtonum($3);
if (rela_addr in section_offset_by_address) {
rela_offset = section_offset_by_address[rela_addr];
} else {
print FILENAME ": *** DT_RELA does not match any section's address";
result = 2;
}
next
}
$2 == "(REL)" {
rel_addr = strtonum($3);
if (rel_addr in section_offset_by_address) {
rel_offset = section_offset_by_address[rel_addr];
} else {
print FILENAME ": *** DT_REL does not match any section's address";
result = 2;
}
next
}
END { exit(result) }