[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[committed] Fix handling of empty .data section
Hi,
When running tests using make check CC="gcc -fuse-ld=gold", we run into:
...
Running /data/dwz/build/../src/testsuite/dwz.tests/dwz-tests.exp ...
dwz: Allocatable section in 1 after non-allocatable ones
dwz: Allocatable section in 2 after non-allocatable ones
dwz: Too few files for multifile optimization
child process exited abnormally
FAIL: /data/dwz/build/../src/testsuite/dwz.tests/pr24542.sh
...
The trigger is that the .data section has the same offset as .debug_info:
...
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
...
[ 5] .data PROGBITS 0000000000401000 00001000
0000000000000000 0000000000000000 WA 0 0 1
[ 6] .bss NOBITS 0000000000401000 00001000
0000000000000000 0000000000000000 WA 0 0 1
[ 7] .debug_info PROGBITS 0000000000000000 00001000
0000000000000047 0000000000000000 0 0 1
...
The problem is here in write_dso:
...
else if (dso->shdr[j].sh_offset < min_shoff && !last_shoff)
continue;
else if ((dso->shdr[j].sh_flags & SHF_ALLOC) != 0)
{
error (0, 0, "Allocatable section in %s after "
"non-allocatable ones", dso->filename);
return 1;
}
...
For the empty .data section, "dso->shdr[j].sh_offset == min_shoff" holds, so
it won't get skipped by the '<' test.
Fix this by skipping an empty section that starts at min_shoff.
Committed to trunk.
Thanks,
- Tom
Fix handling of empty .data section
2019-06-28 Tom de Vries <tdevries@suse.de>
PR dwz/24747
* Makefile (TEST_EXECS): Add start-gold.
(start-gold): New target.
* dwz.c (write_dso): Handle empty allocatable section.
* testsuite/dwz.tests/dwz-tests.exp: Require start-gold for pr24747.sh.
* testsuite/dwz.tests/pr24747.sh: New test.
---
Makefile | 6 +++++-
dwz.c | 5 ++++-
testsuite/dwz.tests/dwz-tests.exp | 3 +++
testsuite/dwz.tests/pr24747.sh | 7 +++++++
4 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 9b02cc1..b2a1fb1 100644
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,8 @@ PWD:=$(shell pwd -P)
TEST_SRC = $(srcdir)/testsuite/dwz.tests
TEST_EXECS = hello dw2-restrict py-section-script dwz-for-test min two-typedef \
- dw2-skip-prologue start implptr-64bit-d2o4a8r8t0 hello-gold-gdb-index
+ dw2-skip-prologue start implptr-64bit-d2o4a8r8t0 hello-gold-gdb-index \
+ start-gold
hello:
$(CC) $(TEST_SRC)/hello.c -o $@ -g
@@ -58,6 +59,9 @@ two-typedef:
start:
$(CC) $(TEST_SRC)/start.c -o $@ -g -nostdlib
+start-gold:
+ $(CC) $(TEST_SRC)/start.c -fuse-ld=gold -o $@ -g -nostdlib || touch $@
+
implptr-64bit-d2o4a8r8t0:
$(CC) $(TEST_SRC)/implptr-64bit-d2o4a8r8t0.S $(TEST_SRC)/main.c -o $@ \
-g || touch $@
diff --git a/dwz.c b/dwz.c
index 342a742..19e8f10 100644
--- a/dwz.c
+++ b/dwz.c
@@ -10673,7 +10673,10 @@ write_dso (DSO *dso, const char *file, struct stat *st)
j = sorted_section_numbers[l];
if (j == dso->ehdr.e_shnum)
continue;
- else if (dso->shdr[j].sh_offset < min_shoff && !last_shoff)
+ else if (!last_shoff
+ && (dso->shdr[j].sh_offset < min_shoff
+ || (dso->shdr[j].sh_offset == min_shoff
+ && dso->shdr[j].sh_size == 0)))
continue;
else if ((dso->shdr[j].sh_flags & SHF_ALLOC) != 0)
{
diff --git a/testsuite/dwz.tests/dwz-tests.exp b/testsuite/dwz.tests/dwz-tests.exp
index e974e7d..ad1ac47 100644
--- a/testsuite/dwz.tests/dwz-tests.exp
+++ b/testsuite/dwz.tests/dwz-tests.exp
@@ -49,6 +49,9 @@ foreach test $tests {
if { $basename == "gold-gdb-index.sh" } {
lappend required_execs "hello-gold-gdb-index"
}
+ if { $basename == "pr24747.sh" } {
+ lappend required_execs "start-gold"
+ }
if { ![istarget x86_64-*-*] } {
if { $basename == "pr24468.sh" } {
unsupported "$test"
diff --git a/testsuite/dwz.tests/pr24747.sh b/testsuite/dwz.tests/pr24747.sh
new file mode 100644
index 0000000..1e555ce
--- /dev/null
+++ b/testsuite/dwz.tests/pr24747.sh
@@ -0,0 +1,7 @@
+cp $execs/start-gold 1
+
+dwz 1
+
+smaller-than.sh 1 $execs/hello
+
+rm -f 1