aboutsummaryrefslogtreecommitdiff
path: root/bfd/peXXigen.c
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@suse.com>2021-03-09 08:52:32 +0100
committerJan Beulich <jbeulich@suse.com>2021-03-09 08:52:32 +0100
commit87fa7d568ddd804fb73bb78e33ae1c22d9fe343c (patch)
tree3b7c6340553f16341999dc7a2bfe6fcfedc5ac54 /bfd/peXXigen.c
parent500e7d4cb32129c8f2a3a4af6fd599f676b4f694 (diff)
downloadgdb-87fa7d568ddd804fb73bb78e33ae1c22d9fe343c.zip
gdb-87fa7d568ddd804fb73bb78e33ae1c22d9fe343c.tar.gz
gdb-87fa7d568ddd804fb73bb78e33ae1c22d9fe343c.tar.bz2
bfd: don't silently wrap or truncate PE image section RVAs
In PE images section addresses get expressed as addresses relative to the image base. Therefore the VA of a section must be no less than the image base, and after subtraction of the image base the resulting value should fit in 32 bits. (The issue is particularly obvious to notice when sections, perhaps because of ELF assumptions, get placed at VA 0 by default. Debugging info sections as well as .comment, when input files are ELF, are a good example. All such sections need proper mentioning in the linker script to avoid this warning.) There are a number of test cases which previously produced bogus images, yet still declared the test a success. Like done for other tests already, force a zero image base for these. This then also allows (and requires) dropping again xfail-s which 39a7b38fac0e ("Fix linker tests to work with 16-bit targets") had added to ld-scripts/default-script*.d (originally as skip-s). This also depends on similar adjustments to testsuite/ld-scripts/map-address.* made by an earlier patch. For ld-scripts/print-memory-usage.* I suppose xcoff could be dropped from the exclusion list by suppressing garbage collection, just like already done in e.g. (as seen in the diff here) ld-scripts/data.*, but I didn't want to make unrelated adjustments.
Diffstat (limited to 'bfd/peXXigen.c')
-rw-r--r--bfd/peXXigen.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c
index 513b593..83bbac5 100644
--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -933,11 +933,13 @@ _bfd_XXi_swap_scnhdr_out (bfd * abfd, void * in, void * out)
memcpy (scnhdr_ext->s_name, scnhdr_int->s_name, sizeof (scnhdr_int->s_name));
- PUT_SCNHDR_VADDR (abfd,
- ((scnhdr_int->s_vaddr
- - pe_data (abfd)->pe_opthdr.ImageBase)
- & 0xffffffff),
- scnhdr_ext->s_vaddr);
+ ss = scnhdr_int->s_vaddr - pe_data (abfd)->pe_opthdr.ImageBase;
+ if (scnhdr_int->s_vaddr < pe_data (abfd)->pe_opthdr.ImageBase)
+ _bfd_error_handler ("%pB:%.8s: section below image base",
+ abfd, scnhdr_int->s_name);
+ else if(ss != (ss & 0xffffffff))
+ _bfd_error_handler ("%pB:%.8s: RVA truncated", abfd, scnhdr_int->s_name);
+ PUT_SCNHDR_VADDR (abfd, ss & 0xffffffff, scnhdr_ext->s_vaddr);
/* NT wants the size data to be rounded up to the next
NT_FILE_ALIGNMENT, but zero if it has no content (as in .bss,