This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] Treat SHT_FINI_ARRAY and SHT_PREINIT_ARRAY as relocatable sections
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Binutils <binutils at sourceware dot org>
- Date: Thu, 30 Aug 2018 08:00:44 -0700
- Subject: Re: [PATCH] Treat SHT_FINI_ARRAY and SHT_PREINIT_ARRAY as relocatable sections
- References: <20180830134530.7278-1-hjl.tools@gmail.com>
On Thu, Aug 30, 2018 at 6:45 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> SHT_FINI_ARRAY and SHT_PREINIT_ARRAY sections are relocatable.
>
> * readelf.c (process_section_headers): Treat SHT_FINI_ARRAY and
> SHT_PREINIT_ARRAY as relocatable sections.
> ---
> binutils/readelf.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/binutils/readelf.c b/binutils/readelf.c
> index 194f1c3e0c..9c675ddf1e 100644
> --- a/binutils/readelf.c
> +++ b/binutils/readelf.c
> @@ -6359,6 +6359,8 @@ process_section_headers (Filedata * filedata)
> && filedata->section_headers[section->sh_info].sh_type != SHT_NOBITS
> && filedata->section_headers[section->sh_info].sh_type != SHT_NOTE
> && filedata->section_headers[section->sh_info].sh_type != SHT_INIT_ARRAY
> + && filedata->section_headers[section->sh_info].sh_type != SHT_FINI_ARRAY
> + && filedata->section_headers[section->sh_info].sh_type != SHT_PREINIT_ARRAY
> /* FIXME: Are other section types valid ? */
> && filedata->section_headers[section->sh_info].sh_type < SHT_LOOS))
> {
> --
> 2.17.1
>
I am checking in this patch.
--
H.J.
From ef1d94658a02e81d1ea8a270d60fb592867a43bd Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 30 Aug 2018 06:41:54 -0700
Subject: [PATCH] Treat SHT_FINI_ARRAY and SHT_PREINIT_ARRAY as relocatable
sections
Since SHT_FINI_ARRAY and SHT_PREINIT_ARRAY sections are relocatable,
this patch fixes readelf and adds a testcase.
binutils/
* readelf.c (process_section_headers): Treat SHT_FINI_ARRAY and
SHT_PREINIT_ARRAY as relocatable sections.
gas/
* testsuite/gas/elf/elf.exp: Run section14.
* testsuite/gas/elf/section14.d: New file.
* testsuite/gas/elf/section14.s: Likewise.
---
binutils/readelf.c | 2 ++
gas/testsuite/gas/elf/elf.exp | 1 +
gas/testsuite/gas/elf/section14.d | 10 ++++++++++
gas/testsuite/gas/elf/section14.s | 18 ++++++++++++++++++
4 files changed, 31 insertions(+)
create mode 100644 gas/testsuite/gas/elf/section14.d
create mode 100644 gas/testsuite/gas/elf/section14.s
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 194f1c3e0c..9c675ddf1e 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -6359,6 +6359,8 @@ process_section_headers (Filedata * filedata)
&& filedata->section_headers[section->sh_info].sh_type != SHT_NOBITS
&& filedata->section_headers[section->sh_info].sh_type != SHT_NOTE
&& filedata->section_headers[section->sh_info].sh_type != SHT_INIT_ARRAY
+ && filedata->section_headers[section->sh_info].sh_type != SHT_FINI_ARRAY
+ && filedata->section_headers[section->sh_info].sh_type != SHT_PREINIT_ARRAY
/* FIXME: Are other section types valid ? */
&& filedata->section_headers[section->sh_info].sh_type < SHT_LOOS))
{
diff --git a/gas/testsuite/gas/elf/elf.exp b/gas/testsuite/gas/elf/elf.exp
index a7c793b0b0..ee4aa57c24 100644
--- a/gas/testsuite/gas/elf/elf.exp
+++ b/gas/testsuite/gas/elf/elf.exp
@@ -219,6 +219,7 @@ if { [is_elf_format] } then {
run_dump_test "section12a"
run_dump_test "section12b"
run_dump_test "section13"
+ run_dump_test "section14"
run_dump_test "dwarf2-1"
run_dump_test "dwarf2-2"
run_dump_test "dwarf2-3"
diff --git a/gas/testsuite/gas/elf/section14.d b/gas/testsuite/gas/elf/section14.d
new file mode 100644
index 0000000000..82b8a776ce
--- /dev/null
+++ b/gas/testsuite/gas/elf/section14.d
@@ -0,0 +1,10 @@
+#name: array sections
+#as: --no-pad-sections
+#readelf: -S --wide
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Addr(ess|) +Off +Size +ES +Flg +Lk +Inf +Al
+ +\[ 0\] +NULL +0+ +0+ +0+ +0+ +0 +0 +0
+#pass
diff --git a/gas/testsuite/gas/elf/section14.s b/gas/testsuite/gas/elf/section14.s
new file mode 100644
index 0000000000..992bbe68a8
--- /dev/null
+++ b/gas/testsuite/gas/elf/section14.s
@@ -0,0 +1,18 @@
+ .section .init_array
+ .align 4
+ .type init_array, %object
+ .size init_array, 4
+init_array:
+ .dc.a foo
+ .section .preinit_array
+ .align 4
+ .type preinit_array, %object
+ .size preinit_array, 4
+preinit_array:
+ .dc.a foo
+ .section .fini_array
+ .align 4
+ .type fini_array, %object
+ .size fini_array, 4
+fini_array:
+ .dc.a foo
--
2.17.1