aboutsummaryrefslogtreecommitdiff
path: root/gas
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2021-01-07 06:42:00 -0800
committerH.J. Lu <hjl.tools@gmail.com>2021-01-07 06:46:55 -0800
commitd1bcae833b32f1408485ce69f844dcd7ded093a8 (patch)
tree0bc66248e5bc96bd1b28e2daf0dc41c0181fadb8 /gas
parent3b288c8e2ed3518c7f4ecd6c73ef1c6dd7469cd1 (diff)
downloadbinutils-d1bcae833b32f1408485ce69f844dcd7ded093a8.zip
binutils-d1bcae833b32f1408485ce69f844dcd7ded093a8.tar.gz
binutils-d1bcae833b32f1408485ce69f844dcd7ded093a8.tar.bz2
ELF: Don't generate unused section symbols
For ELF targets, section symbols are required only for relocations. With -ffunction-sections -fdata-sections, there can be many unused section symbols. Sizes of libstdc++.a on Linux/x86-64 in GCC 11 are With unused section symbols : 39411698 bytes Without unused section symbols: 39227002 bytes The unused section symbols in libstdc++.a occupy more than 180 KB. Add BSF_SECTION_SYM_USED to indicate if a section symbol should be included in the symbol table. The BSF_SECTION_SYM_USED should be set if the section symbol is used for relocation or the section symbol is always included in the symbol table. Add keep_unused_section_symbols to bfd_target to indicate if unused section symbols should be kept. If TARGET_KEEP_UNUSED_SECTION_SYMBOLS is defined as FALSE, unused ection symbols will be removed. Tested on Linux/x86. Other ELF backends need to: 1. Define TARGET_KEEP_UNUSED_SECTION_SYMBOLS to FALSE. 2. Mark used section symbols in assembler backend. 3. Remove unused section symbols from expected assembler and linker outputs. bfd/ PR 27109 * aix386-core.c (core_aix386_vec): Initialize keep_unused_section_symbol to TARGET_KEEP_UNUSED_SECTION_SYMBOLS. * aout-target.h (MY (vec)): Likewise. * binary.c (binary_vec): Likewise. * cisco-core.c (core_cisco_be_vec): Likewise. (core_cisco_le_vec): Likewise. * coff-alpha.c (alpha_ecoff_le_vec): Likewise. * coff-i386.c (TARGET_SYM): Likewise. (TARGET_SYM_BIG): Likewise. * coff-ia64.c (TARGET_SYM): Likewise. * coff-mips.c (mips_ecoff_le_vec): Likewise. (mips_ecoff_be_vec): Likewise. (mips_ecoff_bele_vec): Likewise. * coff-rs6000.c (rs6000_xcoff_vec): Likewise. (powerpc_xcoff_vec): Likewise. * coff-sh.c (sh_coff_small_vec): Likewise. (sh_coff_small_le_vec): Likewise. * coff-tic30.c (tic30_coff_vec): Likewise. * coff-tic54x.c (tic54x_coff0_vec): Likewise. (tic54x_coff0_beh_vec): Likewise. (tic54x_coff1_vec): Likewise. (tic54x_coff1_beh_vec): Likewise. (tic54x_coff2_vec): Likewise. (tic54x_coff2_beh_vec): Likewise. * coff-x86_64.c (TARGET_SYM): Likewise. (TARGET_SYM_BIG): Likewise. * coff64-rs6000.c (rs6000_xcoff64_vec): Likewise. (rs6000_xcoff64_aix_vec): Likewise. * coffcode.h (CREATE_BIG_COFF_TARGET_VEC): Likewise. (CREATE_BIGHDR_COFF_TARGET_VEC): Likewise. (CREATE_LITTLE_COFF_TARGET_VEC): Likewise. * elfxx-target.h (TARGET_BIG_SYM): Likewise. (TARGET_LITTLE_SYM): Likewise. * hppabsd-core.c (core_hppabsd_vec): Likewise. * hpux-core.c (core_hpux_vec): Likewise. * i386msdos.c (i386_msdos_vec): Likewise. * ihex.c (ihex_vec): Likewise. * irix-core.c (core_irix_vec): Likewise. * mach-o-target.c (TARGET_NAME): Likewise. * mmo.c (mmix_mmo_vec): Likewise. * netbsd-core.c (core_netbsd_vec): Likewise. * osf-core.c (core_osf_vec): Likewise. * pdp11.c (MY (vec)): Likewise. * pef.c (pef_vec): Likewise. (pef_xlib_vec): Likewise. * plugin.c (plugin_vec): Likewise. * ppcboot.c (powerpc_boot_vec): Likewise. * ptrace-core.c (core_ptrace_vec): Likewise. * sco5-core.c (core_sco5_vec): Likewise. * som.c (hppa_som_vec): Likewise. * srec.c (srec_vec): Likewise. (symbolsrec_vec): Likewise. * tekhex.c (tekhex_vec): Likewise. * trad-core.c (core_trad_vec): Likewise. * verilog.c (verilog_vec): Likewise. * vms-alpha.c (alpha_vms_vec): Likewise. * vms-lib.c (alpha_vms_lib_txt_vec): Likewise. * wasm-module.c (wasm_vec): Likewise. * xsym.c (sym_vec): Likewise. * elf.c (ignore_section_sym): Return TRUE if BSF_SECTION_SYM_USED isn't set. (elf_map_symbols): Don't include ignored section symbols. * elfcode.h (elf_slurp_symbol_table): Also set BSF_SECTION_SYM_USED on STT_SECTION symbols. * elflink.c (bfd_elf_final_link): Generated section symbols only when emitting relocations or reqired. * elfxx-x86.h (TARGET_KEEP_UNUSED_SECTION_SYMBOLS): New. * syms.c (BSF_SECTION_SYM_USED): New. * targets.c (TARGET_KEEP_UNUSED_SECTION_SYMBOLS): New. (bfd_target): Add keep_unused_section_symbols. (bfd_keep_unused_section_symbols): New. * bfd-in2.h: Regenerated. binutils/ PR 27109 * objcopy.c (copy_object): Handle section symbols for non-relocatable inputs. * testsuite/binutils-all/readelf.exp (readelf_test): Check is_elf_unused_section_symbols. * testsuite/binutils-all/readelf.s-64: Updated. * testsuite/binutils-all/readelf.ss: Likewise. * testsuite/binutils-all/readelf.ss-64: Likewise. * testsuite/binutils-all/readelf.s-64-unused: New file. * testsuite/binutils-all/readelf.ss-64-unused: Likewise. * testsuite/binutils-all/readelf.ss-unused: Likewise. * testsuite/lib/binutils-common.exp (is_elf_unused_section_symbols): New proc. gas/ChangeLog: PR 27109 * read.c (s_reloc): Call symbol_mark_used_in_reloc on the section symbol. * subsegs.c (subseg_set_rest): Set BSF_SECTION_SYM_USED if needed. * write.c (adjust_reloc_syms): Call symbol_mark_used_in_reloc on the section symbol. (set_symtab): Don't generate unused section symbols. (maybe_generate_build_notes): Call symbol_mark_used_in_reloc on the section symbol. * config/obj-elf.c (elf_adjust_symtab): Call symbol_mark_used_in_reloc on the group signature symbol. * testsuite/gas/cfi/cfi-label.d: Remove unused section symbols from expected output. * testsuite/gas/elf/elf.exp (run_elf_list_test): Check is_elf_unused_section_symbols. * testsuite/gas/elf/section2.e: Updated. * testsuite/gas/elf/section2.e-unused: New file. * testsuite/gas/elf/symver.d: Remove unused section symbols. * testsuite/gas/i386/ilp32/elf/symver.d: Likewise. * testsuite/gas/i386/ilp32/x86-64-size-1.d: Likewise. * testsuite/gas/i386/ilp32/x86-64-size-3.d: Likewise. * testsuite/gas/i386/ilp32/x86-64-size-5.d: Likewise. * testsuite/gas/i386/ilp32/x86-64-unwind.d: Likewise. * testsuite/gas/i386/size-1.d: Likewise. * testsuite/gas/i386/size-3.d: Likewise. * testsuite/gas/i386/svr4.d: Likewise. * testsuite/gas/i386/x86-64-size-1.d: Likewise. * testsuite/gas/i386/x86-64-size-3.d: Likewise. * testsuite/gas/i386/x86-64-size-5.d: Likewise. * testsuite/gas/i386/x86-64-unwind.d: Likewise. ld/ PR 27109 * testsuite/ld-elf/export-class.sd: Adjust the expected output. * testsuite/ld-elf/loadaddr3b.d: Likewise. * testsuite/ld-i386/ibt-plt-1.d: Likewise. * testsuite/ld-i386/ibt-plt-2a.d: Likewise. * testsuite/ld-i386/ibt-plt-2c.d: Likewise. * testsuite/ld-i386/ibt-plt-3a.d: Likewise. * testsuite/ld-i386/ibt-plt-3c.d: Likewise. * testsuite/ld-i386/pr19636-1d.d: Likewise. * testsuite/ld-i386/pr19636-1l.d: Likewise. * testsuite/ld-i386/pr19636-2c.d: Likewise. * testsuite/ld-ifunc/ifunc-2-i386-now.d: Likewise. * testsuite/ld-ifunc/ifunc-2-local-i386-now.d: Likewise. * testsuite/ld-ifunc/ifunc-2-local-x86-64-now.d: Likewise. * testsuite/ld-ifunc/ifunc-2-x86-64-now.d: Likewise. * testsuite/ld-ifunc/ifunc-21-x86-64.d: Likewise. * testsuite/ld-ifunc/ifunc-22-x86-64.d: Likewise. * testsuite/ld-ifunc/pr17154-i386-now.d: Likewise. * testsuite/ld-ifunc/pr17154-i386.d: Likewise. * testsuite/ld-ifunc/pr17154-x86-64-now.d: Likewise. * testsuite/ld-ifunc/pr17154-x86-64.d: Likewise. * testsuite/ld-x86-64/bnd-branch-1-now.d: Likewise. * testsuite/ld-x86-64/bnd-ifunc-1-now.d: Likewise. * testsuite/ld-x86-64/bnd-ifunc-2-now.d: Likewise. * testsuite/ld-x86-64/bnd-ifunc-2.d: Likewise. * testsuite/ld-x86-64/bnd-plt-1-now.d: Likewise. * testsuite/ld-x86-64/bnd-plt-1.d: Likewise. * testsuite/ld-x86-64/ibt-plt-1-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-1.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2a-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2a.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2c-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2c.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3a-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3a.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3c-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3c.d: Likewise. * testsuite/ld-x86-64/pr19609-4e.d: Likewise. * testsuite/ld-x86-64/pr19609-6a.d: Likewise. * testsuite/ld-x86-64/pr19609-6b.d: Likewise. * testsuite/ld-x86-64/pr19609-7b.d: Likewise. * testsuite/ld-x86-64/pr19609-7d.d: Likewise. * testsuite/ld-x86-64/pr19636-2l.d: Likewise. * testsuite/ld-x86-64/pr20253-1d.d: Likewise. * testsuite/ld-x86-64/pr20253-1h.d: Likewise. * testsuite/ld-x86-64/pr21038b-now.d: Likewise. * testsuite/ld-x86-64/pr21038b.d: Likewise. * testsuite/ld-x86-64/pr21038c-now.d: Likewise. * testsuite/ld-x86-64/pr21038c.d: Likewise. * testsuite/ld-x86-64/pr23854.d: Likewise. * testsuite/ld-x86-64/pr25416-3.d: Likewise. * testsuite/ld-x86-64/pr25416-4.d: Likewise. * testsuite/ld-i386/plt-pic.pd: Likewise. * testsuite/ld-i386/plt-pic2.dd: Likewise. * testsuite/ld-i386/plt.pd: Likewise. * testsuite/ld-i386/plt2.dd: Likewise. * testsuite/ld-i386/tlsbin.rd: Likewise. * testsuite/ld-i386/tlsbin2.rd: Likewise. * testsuite/ld-i386/tlsbindesc.rd: Likewise. * testsuite/ld-i386/tlsdesc.rd: Likewise. * testsuite/ld-i386/tlsgdesc.rd: Likewise. * testsuite/ld-i386/tlsnopic.rd: Likewise. * testsuite/ld-i386/tlspic.rd: Likewise. * testsuite/ld-i386/tlspic2.rd: Likewise. * testsuite/ld-x86-64/mpx3.dd: Likewise. * testsuite/ld-x86-64/mpx3n.dd: Likewise. * testsuite/ld-x86-64/mpx4.dd: Likewise. * testsuite/ld-x86-64/mpx4n.dd: Likewise. * testsuite/ld-x86-64/pe-x86-64-1.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-2.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-3.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-4.od: Likewise. * testsuite/ld-x86-64/plt.pd: Likewise. * testsuite/ld-x86-64/plt2.dd: Likewise. * testsuite/ld-x86-64/tlsbin.rd: Likewise. * testsuite/ld-x86-64/tlsbin2.rd: Likewise. * testsuite/ld-x86-64/tlsbindesc.rd: Likewise. * testsuite/ld-x86-64/tlsdesc.rd: Likewise. * testsuite/ld-x86-64/tlsgdesc.rd: Likewise. * testsuite/ld-x86-64/tlspic.rd: Likewise. * testsuite/ld-x86-64/tlspic2.rd: Likewise. * testsuite/ld-elf/sec64k.exp: Check is_elf_unused_section_symbols.
Diffstat (limited to 'gas')
-rw-r--r--gas/ChangeLog33
-rw-r--r--gas/config/obj-elf.c3
-rw-r--r--gas/read.c3
-rw-r--r--gas/subsegs.c4
-rw-r--r--gas/testsuite/gas/cfi/cfi-label.d4
-rw-r--r--gas/testsuite/gas/elf/elf.exp6
-rw-r--r--gas/testsuite/gas/elf/section2.e7
-rw-r--r--gas/testsuite/gas/elf/section2.e-unused8
-rw-r--r--gas/testsuite/gas/elf/symver.d4
-rw-r--r--gas/testsuite/gas/i386/ilp32/elf/symver.d4
-rw-r--r--gas/testsuite/gas/i386/ilp32/x86-64-size-1.d24
-rw-r--r--gas/testsuite/gas/i386/ilp32/x86-64-size-3.d16
-rw-r--r--gas/testsuite/gas/i386/ilp32/x86-64-size-5.d12
-rw-r--r--gas/testsuite/gas/i386/ilp32/x86-64-unwind.d6
-rw-r--r--gas/testsuite/gas/i386/size-1.d24
-rw-r--r--gas/testsuite/gas/i386/size-3.d16
-rw-r--r--gas/testsuite/gas/i386/svr4.d3
-rw-r--r--gas/testsuite/gas/i386/x86-64-size-1.d24
-rw-r--r--gas/testsuite/gas/i386/x86-64-size-3.d16
-rw-r--r--gas/testsuite/gas/i386/x86-64-size-5.d12
-rw-r--r--gas/testsuite/gas/i386/x86-64-unwind.d10
-rw-r--r--gas/write.c43
22 files changed, 165 insertions, 117 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog
index 48c21f7..1d34544 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,36 @@
+2021-01-07 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR 27109
+ * read.c (s_reloc): Call symbol_mark_used_in_reloc on the
+ section symbol.
+ * subsegs.c (subseg_set_rest): Set BSF_SECTION_SYM_USED if needed.
+ * write.c (adjust_reloc_syms): Call symbol_mark_used_in_reloc
+ on the section symbol.
+ (set_symtab): Don't generate unused section symbols.
+ (maybe_generate_build_notes): Call symbol_mark_used_in_reloc
+ on the section symbol.
+ * config/obj-elf.c (elf_adjust_symtab): Call
+ symbol_mark_used_in_reloc on the group signature symbol.
+ * testsuite/gas/cfi/cfi-label.d: Remove unused section symbols
+ from expected output.
+ * testsuite/gas/elf/elf.exp (run_elf_list_test): Check
+ is_elf_unused_section_symbols.
+ * testsuite/gas/elf/section2.e: Updated.
+ * testsuite/gas/elf/section2.e-unused: New file.
+ * testsuite/gas/elf/symver.d: Remove unused section symbols.
+ * testsuite/gas/i386/ilp32/elf/symver.d: Likewise.
+ * testsuite/gas/i386/ilp32/x86-64-size-1.d: Likewise.
+ * testsuite/gas/i386/ilp32/x86-64-size-3.d: Likewise.
+ * testsuite/gas/i386/ilp32/x86-64-size-5.d: Likewise.
+ * testsuite/gas/i386/ilp32/x86-64-unwind.d: Likewise.
+ * testsuite/gas/i386/size-1.d: Likewise.
+ * testsuite/gas/i386/size-3.d: Likewise.
+ * testsuite/gas/i386/svr4.d: Likewise.
+ * testsuite/gas/i386/x86-64-size-1.d: Likewise.
+ * testsuite/gas/i386/x86-64-size-3.d: Likewise.
+ * testsuite/gas/i386/x86-64-size-5.d: Likewise.
+ * testsuite/gas/i386/x86-64-unwind.d: Likewise.
+
2021-01-07 Philipp Tomsich <prt@gnu.org>
* config/tc-riscv.c (riscv_multi_subset_supports): Added
diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index 94fa805..6c0a6ae 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -2841,6 +2841,9 @@ elf_adjust_symtab (void)
symbol_table_insert (sy);
}
elf_group_id (s) = symbol_get_bfdsym (sy);
+ /* Mark the group signature symbol as used so that it will be
+ included in the symbol table. */
+ symbol_mark_used_in_reloc (sy);
}
}
diff --git a/gas/read.c b/gas/read.c
index 9d0ba27..be6e3e0 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -4207,6 +4207,9 @@ s_reloc (int ignore ATTRIBUTE_UNUSED)
goto err_out;
case O_constant:
exp.X_add_symbol = section_symbol (now_seg);
+ /* Mark the section symbol used in relocation so that it will be
+ included in the symbol table. */
+ symbol_mark_used_in_reloc (exp.X_add_symbol);
exp.X_op = O_symbol;
/* Fallthru */
case O_symbol:
diff --git a/gas/subsegs.c b/gas/subsegs.c
index 8e4b310..191879e 100644
--- a/gas/subsegs.c
+++ b/gas/subsegs.c
@@ -89,6 +89,10 @@ subseg_set_rest (segT seg, subsegT subseg)
seginfo = seg_info (seg);
+ /* Should the section symbol be kept? */
+ if (bfd_keep_unused_section_symbols (stdoutput))
+ seg->symbol->flags |= BSF_SECTION_SYM_USED;
+
/* Attempt to find or make a frchain for that subsection.
We keep the list sorted by subsection number. */
for (frcP = *(lastPP = &seginfo->frchainP);
diff --git a/gas/testsuite/gas/cfi/cfi-label.d b/gas/testsuite/gas/cfi/cfi-label.d
index 0350b57..c650713 100644
--- a/gas/testsuite/gas/cfi/cfi-label.d
+++ b/gas/testsuite/gas/cfi/cfi-label.d
@@ -6,11 +6,9 @@
SYMBOL TABLE:
0*00 l d \.text 0*00 \.text
-0*00 l d \.data 0*00 \.data
-0*00 l d \.bss 0*00 \.bss
+#...
0*00 l F \.text 0*04 cfilabel
0*2f l \.eh_frame 0*00 cfi2
-0*00 l d \.eh_frame 0*00 \.eh_frame
0*2b g \.eh_frame 0*00 cfi1
diff --git a/gas/testsuite/gas/elf/elf.exp b/gas/testsuite/gas/elf/elf.exp
index 5cfb7a6..a0f98ed 100644
--- a/gas/testsuite/gas/elf/elf.exp
+++ b/gas/testsuite/gas/elf/elf.exp
@@ -54,7 +54,11 @@ proc run_elf_list_test { name suffix opts readelf_opts readelf_pipe } {
# We're testing bits in obj-elf -- don't run on anything else.
if { [is_elf_format] } then {
- set target_machine ""
+ if { [is_elf_unused_section_symbols ] } {
+ set target_machine -unused
+ } else {
+ set target_machine ""
+ }
set dump_opts ""
if {[istarget "arc*-*-*"]} {
set target_machine -arc
diff --git a/gas/testsuite/gas/elf/section2.e b/gas/testsuite/gas/elf/section2.e
index 9b50798..8b13789 100644
--- a/gas/testsuite/gas/elf/section2.e
+++ b/gas/testsuite/gas/elf/section2.e
@@ -1,8 +1 @@
-Symbol table '.symtab' contains 5 entries:
- +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
- +0: 0+0 +0 +NOTYPE +LOCAL +DEFAULT +UND
- +1: 0+0 +0 +SECTION +LOCAL +DEFAULT +1
- +2: 0+0 +0 +SECTION +LOCAL +DEFAULT +2
- +3: 0+0 +0 +SECTION +LOCAL +DEFAULT +3
- +4: 0+0 +0 +SECTION +LOCAL +DEFAULT +4
diff --git a/gas/testsuite/gas/elf/section2.e-unused b/gas/testsuite/gas/elf/section2.e-unused
new file mode 100644
index 0000000..9b50798
--- /dev/null
+++ b/gas/testsuite/gas/elf/section2.e-unused
@@ -0,0 +1,8 @@
+
+Symbol table '.symtab' contains 5 entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+ +0: 0+0 +0 +NOTYPE +LOCAL +DEFAULT +UND
+ +1: 0+0 +0 +SECTION +LOCAL +DEFAULT +1
+ +2: 0+0 +0 +SECTION +LOCAL +DEFAULT +2
+ +3: 0+0 +0 +SECTION +LOCAL +DEFAULT +3
+ +4: 0+0 +0 +SECTION +LOCAL +DEFAULT +4
diff --git a/gas/testsuite/gas/elf/symver.d b/gas/testsuite/gas/elf/symver.d
index 7fcc62a..2292e32 100644
--- a/gas/testsuite/gas/elf/symver.d
+++ b/gas/testsuite/gas/elf/symver.d
@@ -8,10 +8,6 @@
.*: file format .*
SYMBOL TABLE:
-
-0+000 l.*d.*\.text.*0+000.*
-0+000 l.*d.*\.data.*0+000.*
-0+000 l.*d.*\.bss.*0+000.*
#...
0+000 l.*O.*\.data.*0+004 x
#...
diff --git a/gas/testsuite/gas/i386/ilp32/elf/symver.d b/gas/testsuite/gas/i386/ilp32/elf/symver.d
index 7f69d66..3acf148 100644
--- a/gas/testsuite/gas/i386/ilp32/elf/symver.d
+++ b/gas/testsuite/gas/i386/ilp32/elf/symver.d
@@ -9,10 +9,6 @@
.*: file format .*
SYMBOL TABLE:
-
-0+000 l.*d.*\.text.*0+000.*
-0+000 l.*d.*\.data.*0+000.*
-0+000 l.*d.*\.bss.*0+000.*
#...
0+000 l.*O.*\.data.*0+004 x
#...
diff --git a/gas/testsuite/gas/i386/ilp32/x86-64-size-1.d b/gas/testsuite/gas/i386/ilp32/x86-64-size-1.d
index e5b74fa..64b052d 100644
--- a/gas/testsuite/gas/i386/ilp32/x86-64-size-1.d
+++ b/gas/testsuite/gas/i386/ilp32/x86-64-size-1.d
@@ -6,19 +6,19 @@
Relocation section '.rela.text' at offset .* contains 9 entries:
Offset Info Type Sym.Value Sym. Name \+ Addend
-0+1 00000420 R_X86_64_SIZE32 00000000 xxx \+ 0
-0+6 00000420 R_X86_64_SIZE32 00000000 xxx - 8
-0+b 00000420 R_X86_64_SIZE32 00000000 xxx \+ 8
-0+10 00000520 R_X86_64_SIZE32 00000000 yyy \+ 0
-0+15 00000520 R_X86_64_SIZE32 00000000 yyy - 10
-0+1a 00000520 R_X86_64_SIZE32 00000000 yyy \+ 10
-0+1f 00000620 R_X86_64_SIZE32 00000020 zzz \+ 0
-0+24 00000620 R_X86_64_SIZE32 00000020 zzz - 20
-0+29 00000620 R_X86_64_SIZE32 00000020 zzz \+ 20
+0+1 00000120 R_X86_64_SIZE32 00000000 xxx \+ 0
+0+6 00000120 R_X86_64_SIZE32 00000000 xxx - 8
+0+b 00000120 R_X86_64_SIZE32 00000000 xxx \+ 8
+0+10 00000220 R_X86_64_SIZE32 00000000 yyy \+ 0
+0+15 00000220 R_X86_64_SIZE32 00000000 yyy - 10
+0+1a 00000220 R_X86_64_SIZE32 00000000 yyy \+ 10
+0+1f 00000320 R_X86_64_SIZE32 00000020 zzz \+ 0
+0+24 00000320 R_X86_64_SIZE32 00000020 zzz - 20
+0+29 00000320 R_X86_64_SIZE32 00000020 zzz \+ 20
Relocation section '.rela.data' at offset .* contains 3 entries:
Offset Info Type Sym.Value Sym. Name \+ Addend
-0+50 00000420 R_X86_64_SIZE32 00000000 xxx - 1
-0+54 00000520 R_X86_64_SIZE32 00000000 yyy \+ 2
-0+58 00000620 R_X86_64_SIZE32 00000020 zzz \+ 0
+0+50 00000120 R_X86_64_SIZE32 00000000 xxx - 1
+0+54 00000220 R_X86_64_SIZE32 00000000 yyy \+ 2
+0+58 00000320 R_X86_64_SIZE32 00000020 zzz \+ 0
#pass
diff --git a/gas/testsuite/gas/i386/ilp32/x86-64-size-3.d b/gas/testsuite/gas/i386/ilp32/x86-64-size-3.d
index 6f96134..65f6890 100644
--- a/gas/testsuite/gas/i386/ilp32/x86-64-size-3.d
+++ b/gas/testsuite/gas/i386/ilp32/x86-64-size-3.d
@@ -6,15 +6,15 @@
Relocation section '.rela.text' at offset .* contains 6 entries:
Offset Info Type Sym.Value Sym. Name \+ Addend
-0+1 00000620 R_X86_64_SIZE32 00000000 xxx \+ 0
-0+6 00000620 R_X86_64_SIZE32 00000000 xxx - 8
-0+b 00000620 R_X86_64_SIZE32 00000000 xxx \+ 8
-0+10 00000720 R_X86_64_SIZE32 00000000 yyy \+ 0
-0+15 00000720 R_X86_64_SIZE32 00000000 yyy - 10
-0+1a 00000720 R_X86_64_SIZE32 00000000 yyy \+ 10
+0+1 00000120 R_X86_64_SIZE32 00000000 xxx \+ 0
+0+6 00000120 R_X86_64_SIZE32 00000000 xxx - 8
+0+b 00000120 R_X86_64_SIZE32 00000000 xxx \+ 8
+0+10 00000220 R_X86_64_SIZE32 00000000 yyy \+ 0
+0+15 00000220 R_X86_64_SIZE32 00000000 yyy - 10
+0+1a 00000220 R_X86_64_SIZE32 00000000 yyy \+ 10
Relocation section '.rela.tdata' at offset .* contains 2 entries:
Offset Info Type Sym.Value Sym. Name \+ Addend
-0+50 00000620 R_X86_64_SIZE32 00000000 xxx - 1
-0+54 00000720 R_X86_64_SIZE32 00000000 yyy \+ 2
+0+50 00000120 R_X86_64_SIZE32 00000000 xxx - 1
+0+54 00000220 R_X86_64_SIZE32 00000000 yyy \+ 2
#pass
diff --git a/gas/testsuite/gas/i386/ilp32/x86-64-size-5.d b/gas/testsuite/gas/i386/ilp32/x86-64-size-5.d
index 8ce06b0..4571a48 100644
--- a/gas/testsuite/gas/i386/ilp32/x86-64-size-5.d
+++ b/gas/testsuite/gas/i386/ilp32/x86-64-size-5.d
@@ -6,13 +6,13 @@
Relocation section '.rela.text' at offset .* contains 3 entries:
Offset Info Type Sym.Value Sym. Name \+ Addend
-0+2 00000421 R_X86_64_SIZE64 00000000 xxx \+ 0
-0+c 00000421 R_X86_64_SIZE64 00000000 xxx - 8
-0+16 00000421 R_X86_64_SIZE64 00000000 xxx \+ 8
+0+2 00000121 R_X86_64_SIZE64 00000000 xxx \+ 0
+0+c 00000121 R_X86_64_SIZE64 00000000 xxx - 8
+0+16 00000121 R_X86_64_SIZE64 00000000 xxx \+ 8
Relocation section '.rela.data' at offset .* contains 3 entries:
Offset Info Type Sym.Value Sym. Name \+ Addend
-0+50 00000421 R_X86_64_SIZE64 00000000 xxx - 1
-0+58 00000621 R_X86_64_SIZE64 00000000 yyy \+ c8
-0+60 00000521 R_X86_64_SIZE64 00000020 zzz \+ 0
+0+50 00000121 R_X86_64_SIZE64 00000000 xxx - 1
+0+58 00000321 R_X86_64_SIZE64 00000000 yyy \+ c8
+0+60 00000221 R_X86_64_SIZE64 00000020 zzz \+ 0
#pass
diff --git a/gas/testsuite/gas/i386/ilp32/x86-64-unwind.d b/gas/testsuite/gas/i386/ilp32/x86-64-unwind.d
index bd532b7..274ddb0 100644
--- a/gas/testsuite/gas/i386/ilp32/x86-64-unwind.d
+++ b/gas/testsuite/gas/i386/ilp32/x86-64-unwind.d
@@ -3,7 +3,7 @@
#readelf: -S
#name: x86-64 (ILP32) unwind
-There are 8 section headers, starting at offset 0x[0-9a-f]+:
+There are 6 section headers, starting at offset 0x[0-9a-f]+:
Section Headers:
\[Nr\] Name Type Addr Off Size ES Flg Lk Inf Al
@@ -12,8 +12,6 @@ Section Headers:
\[ 2\] .data PROGBITS 00000000 000034 000000 00 WA 0 0 1
\[ 3\] .bss NOBITS 00000000 000034 000000 00 WA 0 0 1
\[ 4\] .eh_frame X86_64_UNWIND 00000000 000034 000008 00 A 0 0 1
- \[ 5\] .symtab SYMTAB 00000000 [0-9a-f]+ 000050 10 6 5 4
- \[ 6\] .strtab STRTAB 00000000 [0-9a-f]+ 000001 00 . 0 0 1
- \[ 7\] .shstrtab STRTAB 00000000 [0-9a-f]+ 000036 00 . 0 0 1
+ \[ 5\] .shstrtab STRTAB 00000000 [0-9a-f]+ 000026 00 . 0 0 1
Key to Flags:
#pass
diff --git a/gas/testsuite/gas/i386/size-1.d b/gas/testsuite/gas/i386/size-1.d
index d582bbe..b187e5d 100644
--- a/gas/testsuite/gas/i386/size-1.d
+++ b/gas/testsuite/gas/i386/size-1.d
@@ -5,19 +5,19 @@
Relocation section '.rel.text' at offset .* contains 9 entries:
Offset Info Type Sym.Value Sym. Name
-0+1 00000426 R_386_SIZE32 00000000 xxx
-0+6 00000426 R_386_SIZE32 00000000 xxx
-0+b 00000426 R_386_SIZE32 00000000 xxx
-0+10 00000526 R_386_SIZE32 00000000 yyy
-0+15 00000526 R_386_SIZE32 00000000 yyy
-0+1a 00000526 R_386_SIZE32 00000000 yyy
-0+1f 00000626 R_386_SIZE32 00000020 zzz
-0+24 00000626 R_386_SIZE32 00000020 zzz
-0+29 00000626 R_386_SIZE32 00000020 zzz
+0+1 00000126 R_386_SIZE32 00000000 xxx
+0+6 00000126 R_386_SIZE32 00000000 xxx
+0+b 00000126 R_386_SIZE32 00000000 xxx
+0+10 00000226 R_386_SIZE32 00000000 yyy
+0+15 00000226 R_386_SIZE32 00000000 yyy
+0+1a 00000226 R_386_SIZE32 00000000 yyy
+0+1f 00000326 R_386_SIZE32 00000020 zzz
+0+24 00000326 R_386_SIZE32 00000020 zzz
+0+29 00000326 R_386_SIZE32 00000020 zzz
Relocation section '.rel.data' at offset .* contains 3 entries:
Offset Info Type Sym.Value Sym. Name
-0+50 00000426 R_386_SIZE32 00000000 xxx
-0+54 00000526 R_386_SIZE32 00000000 yyy
-0+58 00000626 R_386_SIZE32 00000020 zzz
+0+50 00000126 R_386_SIZE32 00000000 xxx
+0+54 00000226 R_386_SIZE32 00000000 yyy
+0+58 00000326 R_386_SIZE32 00000020 zzz
#pass
diff --git a/gas/testsuite/gas/i386/size-3.d b/gas/testsuite/gas/i386/size-3.d
index 2b08707..b45811c 100644
--- a/gas/testsuite/gas/i386/size-3.d
+++ b/gas/testsuite/gas/i386/size-3.d
@@ -5,15 +5,15 @@
Relocation section '.rel.text' at offset .* contains 6 entries:
Offset Info Type Sym.Value Sym. Name
-0+1 00000626 R_386_SIZE32 00000000 xxx
-0+6 00000626 R_386_SIZE32 00000000 xxx
-0+b 00000626 R_386_SIZE32 00000000 xxx
-0+10 00000726 R_386_SIZE32 00000000 yyy
-0+15 00000726 R_386_SIZE32 00000000 yyy
-0+1a 00000726 R_386_SIZE32 00000000 yyy
+0+1 00000126 R_386_SIZE32 00000000 xxx
+0+6 00000126 R_386_SIZE32 00000000 xxx
+0+b 00000126 R_386_SIZE32 00000000 xxx
+0+10 00000226 R_386_SIZE32 00000000 yyy
+0+15 00000226 R_386_SIZE32 00000000 yyy
+0+1a 00000226 R_386_SIZE32 00000000 yyy
Relocation section '.rel.tdata' at offset .* contains 2 entries:
Offset Info Type Sym.Value Sym. Name
-0+50 00000626 R_386_SIZE32 00000000 xxx
-0+54 00000726 R_386_SIZE32 00000000 yyy
+0+50 00000126 R_386_SIZE32 00000000 xxx
+0+54 00000226 R_386_SIZE32 00000000 yyy
#pass
diff --git a/gas/testsuite/gas/i386/svr4.d b/gas/testsuite/gas/i386/svr4.d
index 3a46354..2820506 100644
--- a/gas/testsuite/gas/i386/svr4.d
+++ b/gas/testsuite/gas/i386/svr4.d
@@ -4,9 +4,6 @@
.*: +file format .*
SYMBOL TABLE:
-0+00 .* \.text[ ]+0+ \.text
-0+00 .* \.data[ ]+0+ \.data
-0+00 .* \.bss[ ]+0+ \.bss
0+00 .* \.text[ ]+0+ svr4
0+04 .* \*ABS\*[ ]+0+ a
0+03 .* \*ABS\*[ ]+0+ b
diff --git a/gas/testsuite/gas/i386/x86-64-size-1.d b/gas/testsuite/gas/i386/x86-64-size-1.d
index 657408c..57db899 100644
--- a/gas/testsuite/gas/i386/x86-64-size-1.d
+++ b/gas/testsuite/gas/i386/x86-64-size-1.d
@@ -6,19 +6,19 @@
Relocation section '.rela.text' at offset .* contains 9 entries:
Offset Info Type Sym. Value Sym. Name \+ Addend
-0+1 000400000020 R_X86_64_SIZE32 0000000000000000 xxx \+ 0
-0+6 000400000020 R_X86_64_SIZE32 0000000000000000 xxx - 8
-0+b 000400000020 R_X86_64_SIZE32 0000000000000000 xxx \+ 8
-0+10 000500000020 R_X86_64_SIZE32 0000000000000000 yyy \+ 0
-0+15 000500000020 R_X86_64_SIZE32 0000000000000000 yyy - 10
-0+1a 000500000020 R_X86_64_SIZE32 0000000000000000 yyy \+ 10
-0+1f 000600000020 R_X86_64_SIZE32 0000000000000020 zzz \+ 0
-0+24 000600000020 R_X86_64_SIZE32 0000000000000020 zzz - 20
-0+29 000600000020 R_X86_64_SIZE32 0000000000000020 zzz \+ 20
+0+1 000100000020 R_X86_64_SIZE32 0000000000000000 xxx \+ 0
+0+6 000100000020 R_X86_64_SIZE32 0000000000000000 xxx - 8
+0+b 000100000020 R_X86_64_SIZE32 0000000000000000 xxx \+ 8
+0+10 000200000020 R_X86_64_SIZE32 0000000000000000 yyy \+ 0
+0+15 000200000020 R_X86_64_SIZE32 0000000000000000 yyy - 10
+0+1a 000200000020 R_X86_64_SIZE32 0000000000000000 yyy \+ 10
+0+1f 000300000020 R_X86_64_SIZE32 0000000000000020 zzz \+ 0
+0+24 000300000020 R_X86_64_SIZE32 0000000000000020 zzz - 20
+0+29 000300000020 R_X86_64_SIZE32 0000000000000020 zzz \+ 20
Relocation section '.rela.data' at offset .* contains 3 entries:
Offset Info Type Sym. Value Sym. Name \+ Addend
-0+50 000400000020 R_X86_64_SIZE32 0000000000000000 xxx - 1
-0+54 000500000020 R_X86_64_SIZE32 0000000000000000 yyy \+ 2
-0+58 000600000020 R_X86_64_SIZE32 0000000000000020 zzz \+ 0
+0+50 000100000020 R_X86_64_SIZE32 0000000000000000 xxx - 1
+0+54 000200000020 R_X86_64_SIZE32 0000000000000000 yyy \+ 2
+0+58 000300000020 R_X86_64_SIZE32 0000000000000020 zzz \+ 0
#pass
diff --git a/gas/testsuite/gas/i386/x86-64-size-3.d b/gas/testsuite/gas/i386/x86-64-size-3.d
index 943a64e..4688dc9 100644
--- a/gas/testsuite/gas/i386/x86-64-size-3.d
+++ b/gas/testsuite/gas/i386/x86-64-size-3.d
@@ -6,15 +6,15 @@
Relocation section '.rela.text' at offset .* contains 6 entries:
Offset Info Type Sym. Value Sym. Name \+ Addend
-0+1 000600000020 R_X86_64_SIZE32 0000000000000000 xxx \+ 0
-0+6 000600000020 R_X86_64_SIZE32 0000000000000000 xxx - 8
-0+b 000600000020 R_X86_64_SIZE32 0000000000000000 xxx \+ 8
-0+10 000700000020 R_X86_64_SIZE32 0000000000000000 yyy \+ 0
-0+15 000700000020 R_X86_64_SIZE32 0000000000000000 yyy - 10
-0+1a 000700000020 R_X86_64_SIZE32 0000000000000000 yyy \+ 10
+0+1 000100000020 R_X86_64_SIZE32 0000000000000000 xxx \+ 0
+0+6 000100000020 R_X86_64_SIZE32 0000000000000000 xxx - 8
+0+b 000100000020 R_X86_64_SIZE32 0000000000000000 xxx \+ 8
+0+10 000200000020 R_X86_64_SIZE32 0000000000000000 yyy \+ 0
+0+15 000200000020 R_X86_64_SIZE32 0000000000000000 yyy - 10
+0+1a 000200000020 R_X86_64_SIZE32 0000000000000000 yyy \+ 10
Relocation section '.rela.tdata' at offset .* contains 2 entries:
Offset Info Type Sym. Value Sym. Name \+ Addend
-0+50 000600000020 R_X86_64_SIZE32 0000000000000000 xxx - 1
-0+54 000700000020 R_X86_64_SIZE32 0000000000000000 yyy \+ 2
+0+50 000100000020 R_X86_64_SIZE32 0000000000000000 xxx - 1
+0+54 000200000020 R_X86_64_SIZE32 0000000000000000 yyy \+ 2
#pass
diff --git a/gas/testsuite/gas/i386/x86-64-size-5.d b/gas/testsuite/gas/i386/x86-64-size-5.d
index c34d0ee..d18ffcd 100644
--- a/gas/testsuite/gas/i386/x86-64-size-5.d
+++ b/gas/testsuite/gas/i386/x86-64-size-5.d
@@ -5,13 +5,13 @@
Relocation section '.rela.text' at offset .* contains 3 entries:
Offset Info Type Sym. Value Sym. Name \+ Addend
-0+2 000400000021 R_X86_64_SIZE64 0000000000000000 xxx \+ 0
-0+c 000400000021 R_X86_64_SIZE64 0000000000000000 xxx - 8
-0+16 000400000021 R_X86_64_SIZE64 0000000000000000 xxx \+ 8
+0+2 000100000021 R_X86_64_SIZE64 0000000000000000 xxx \+ 0
+0+c 000100000021 R_X86_64_SIZE64 0000000000000000 xxx - 8
+0+16 000100000021 R_X86_64_SIZE64 0000000000000000 xxx \+ 8
Relocation section '.rela.data' at offset .* contains 3 entries:
Offset Info Type Sym. Value Sym. Name \+ Addend
-0+50 000400000021 R_X86_64_SIZE64 0000000000000000 xxx - 1
-0+58 000600000021 R_X86_64_SIZE64 0000000000000000 yyy \+ c8
-0+60 000500000021 R_X86_64_SIZE64 0000000000000020 zzz \+ 0
+0+50 000100000021 R_X86_64_SIZE64 0000000000000000 xxx - 1
+0+58 000300000021 R_X86_64_SIZE64 0000000000000000 yyy \+ c8
+0+60 000200000021 R_X86_64_SIZE64 0000000000000020 zzz \+ 0
#pass
diff --git a/gas/testsuite/gas/i386/x86-64-unwind.d b/gas/testsuite/gas/i386/x86-64-unwind.d
index 7f8d94f..ca30472 100644
--- a/gas/testsuite/gas/i386/x86-64-unwind.d
+++ b/gas/testsuite/gas/i386/x86-64-unwind.d
@@ -2,7 +2,7 @@
#readelf: -S
#name: x86-64 unwind
-There are 8 section headers, starting at offset 0x[0-9a-f]+:
+There are 6 section headers, starting at offset 0x[0-9a-f]+:
Section Headers:
\[Nr\] Name Type Address Offset
@@ -17,11 +17,7 @@ Section Headers:
0000000000000000 0000000000000000 WA 0 0 1
\[ 4\] \.eh_frame X86_64_UNWIND 0000000000000000 00000040
0000000000000008 0000000000000000 A 0 0 1
- \[ 5\] \.symtab SYMTAB 0000000000000000 [0-9a-f]+
- 0000000000000078 0000000000000018 6 5 8
- \[ 6\] \.strtab STRTAB 0000000000000000 [0-9a-f]+
- 0000000000000001 0000000000000000 . 0 0 1
- \[ 7\] \.shstrtab STRTAB 0000000000000000 [0-9a-f]+
- 0000000000000036 0000000000000000 . 0 0 1
+ \[ 5\] \.shstrtab STRTAB 0000000000000000 [0-9a-f]+
+ 0000000000000026 0000000000000000 . 0 0 1
Key to Flags:
#...
diff --git a/gas/write.c b/gas/write.c
index ca14b37..75ba971 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -848,7 +848,12 @@ adjust_reloc_syms (bfd *abfd ATTRIBUTE_UNUSED,
/* Since we're reducing to section symbols, don't attempt to reduce
anything that's already using one. */
if (symbol_section_p (sym))
- continue;
+ {
+ /* Mark the section symbol used in relocation so that it will
+ be included in the symbol table. */
+ symbol_mark_used_in_reloc (sym);
+ continue;
+ }
symsec = S_GET_SEGMENT (sym);
if (symsec == NULL)
@@ -1747,10 +1752,13 @@ set_symtab (void)
/* Count symbols. We can't rely on a count made by the loop in
write_object_file, because *_frob_file may add a new symbol or
- two. */
+ two. Generate unused section symbols only if needed. */
nsyms = 0;
for (symp = symbol_rootP; symp; symp = symbol_next (symp))
- nsyms++;
+ if (bfd_keep_unused_section_symbols (stdoutput)
+ || !symbol_section_p (symp)
+ || symbol_used_in_reloc_p (symp))
+ nsyms++;
if (nsyms)
{
@@ -1759,15 +1767,22 @@ set_symtab (void)
asympp = (asymbol **) bfd_alloc (stdoutput, amt);
symp = symbol_rootP;
- for (i = 0; i < nsyms; i++, symp = symbol_next (symp))
- {
- asympp[i] = symbol_get_bfdsym (symp);
- if (asympp[i]->flags != BSF_SECTION_SYM
- || !(bfd_is_const_section (asympp[i]->section)
- && asympp[i]->section->symbol == asympp[i]))
- asympp[i]->flags |= BSF_KEEP;
- symbol_mark_written (symp);
- }
+ for (i = 0; i < nsyms; symp = symbol_next (symp))
+ if (bfd_keep_unused_section_symbols (stdoutput)
+ || !symbol_section_p (symp)
+ || symbol_used_in_reloc_p (symp))
+ {
+ asympp[i] = symbol_get_bfdsym (symp);
+ if (asympp[i]->flags != BSF_SECTION_SYM
+ || !(bfd_is_const_section (asympp[i]->section)
+ && asympp[i]->section->symbol == asympp[i]))
+ asympp[i]->flags |= BSF_KEEP;
+ symbol_mark_written (symp);
+ /* Include this section symbol in the symbol table. */
+ if (symbol_section_p (symp))
+ asympp[i]->flags |= BSF_SECTION_SYM_USED;
+ i++;
+ }
}
else
asympp = 0;
@@ -2058,6 +2073,10 @@ maybe_generate_build_notes (void)
bfd_section_size (bsym->section),
note);
+ /* Mark the section symbol used in relocation so that it will be
+ included in the symbol table. */
+ symbol_mark_used_in_reloc (sym);
+
total_size += note_size;
/* FIXME: Maybe add a note recording the assembler command line and version ? */
}