aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2018-05-21 20:39:09 -0700
committerH.J. Lu <hjl.tools@gmail.com>2018-05-21 20:39:30 -0700
commit34a87bb07a4a3b2202fc25167a6b0f12575edc87 (patch)
tree1e5f01a95feb8860d22986e8131f367376e8a1dd
parentbae363f1146378207e1dffe5f23845644a1d0b7a (diff)
downloadgdb-34a87bb07a4a3b2202fc25167a6b0f12575edc87.zip
gdb-34a87bb07a4a3b2202fc25167a6b0f12575edc87.tar.gz
gdb-34a87bb07a4a3b2202fc25167a6b0f12575edc87.tar.bz2
ld: Hide symbols defined by HIDDEN/PROVIDE_HIDDEN
There should be no difference in output for symbols defined by HIDDEN or PROVIDE_HIDDEN assignments whether they are explicitly marked as hidden or not. This patch adds a new BFD function, bfd_link_hide_symbol, to hide symbols defined by HIDDEN and PROVIDE_HIDDEN assignments. bfd PR ld/23201 * aout-target.h (MY_bfd_link_hide_symbol): New. * aout-tic30.c (MY_bfd_link_hide_symbol): Likewise. * binary.c (binary_bfd_link_hide_symbol): Likewise. * coff-alpha.c (_bfd_ecoff_bfd_link_hide_symbol): Likewise. * coff-mips.c (_bfd_ecoff_bfd_link_hide_symbol): Likewise. * coff-rs6000.c (_bfd_xcoff_bfd_link_hide_symbol): Likewise. * coffcode.h (coff_bfd_link_hide_symbol): Likewise. * elf-bfd.h (_bfd_elf_link_hide_symbol): Likewise. * elfxx-target.h (bfd_elfNN_bfd_link_hide_symbol): Likewise. * i386msdos.c (msdos_bfd_link_hide_symbol): Likewise. * ihex.c (ihex_bfd_link_hide_symbol): Likewise. * libbfd-in.h (_bfd_nolink_bfd_link_hide_symbol): Likewise. * linker.c (_bfd_generic_link_hide_symbol): Likewise. (bfd_link_hide_symbol): Likewise. * mach-o-target.c (bfd_mach_o_bfd_link_hide_symbol): Likewise. * mmo.c (mmo_bfd_link_hide_symbol): Likewise. * pef.c (bfd_pef_bfd_link_hide_symbol): Likewise. * plugin.c (bfd_plugin_bfd_link_hide_symbol): Likewise. * ppcboot.c (ppcboot_bfd_link_hide_symbol): Likewise. * som.c (som_bfd_link_hide_symbol): Likewise. * srec.c (srec_bfd_link_hide_symbol): Likewise. * tekhex.c (tekhex_bfd_link_hide_symbol): Likewise. * vms-alpha.c (vms_bfd_link_hide_symbol): Likewise. (alpha_vms_bfd_link_hide_symbol): Likewise. * xsym.c (bfd_sym_bfd_link_hide_symbol): Likewise. * coff64-rs6000.c (rs6000_xcoff64_vec): Add _bfd_generic_link_hide_symbol. (rs6000_xcoff64_aix_vec): Likewise. * elflink.c (bfd_elf_record_link_assignment): Don't make forced local symbol dynamic. (_bfd_elf_link_hide_symbol): New function. * elfxx-x86.c (_bfd_x86_elf_link_symbol_references_local): Don't check root.ldscript_def. * targets.c (bfd_target): Add _bfd_link_hide_symbol. (BFD_JUMP_TABLE_LINK): Add NAME##_bfd_link_hide_symbol. * bfd-in2.h: Regenerated. * libbfd.h: Likewise. ld/ PR ld/23201 * ldexp.c (exp_fold_tree_1): Call bfd_link_hide_symbol to hide a symbol. * testsuite/ld-elf/provide-hidden-dynabs.nd: Removed. * testsuite/ld-elf/provide-hidden-dynsec.nd: Likewise. * testsuite/ld-elf/provide-hidden.exp: Replace provide-hidden-dynsec.nd with provide-hidden-sec.nd and provide-hidden-dyn.nd. Replace provide-hidden-dynabs.nd with provide-hidden-abs.nd and provide-hidden-dyn.nd. * testsuite/ld-i386/pr23189.d: Expect no dynamic relocation. * testsuite/ld-x86-64/pr23189.d: Likewise.
-rw-r--r--bfd/ChangeLog41
-rw-r--r--bfd/aout-target.h3
-rw-r--r--bfd/aout-tic30.c3
-rw-r--r--bfd/bfd-in2.h12
-rw-r--r--bfd/binary.c1
-rw-r--r--bfd/coff-alpha.c1
-rw-r--r--bfd/coff-mips.c1
-rw-r--r--bfd/coff-rs6000.c1
-rw-r--r--bfd/coff64-rs6000.c2
-rw-r--r--bfd/coffcode.h4
-rw-r--r--bfd/elf-bfd.h2
-rw-r--r--bfd/elflink.c21
-rw-r--r--bfd/elfxx-target.h4
-rw-r--r--bfd/elfxx-x86.c10
-rw-r--r--bfd/i386msdos.c1
-rw-r--r--bfd/ihex.c1
-rw-r--r--bfd/libbfd-in.h2
-rw-r--r--bfd/libbfd.h2
-rw-r--r--bfd/linker.c26
-rw-r--r--bfd/mach-o-target.c1
-rw-r--r--bfd/mmo.c1
-rw-r--r--bfd/pef.c1
-rw-r--r--bfd/plugin.c1
-rw-r--r--bfd/ppcboot.c1
-rw-r--r--bfd/som.c1
-rw-r--r--bfd/srec.c1
-rw-r--r--bfd/targets.c5
-rw-r--r--bfd/tekhex.c1
-rw-r--r--bfd/vms-alpha.c2
-rw-r--r--bfd/xsym.c1
-rw-r--r--ld/ChangeLog14
-rw-r--r--ld/ldexp.c3
-rw-r--r--ld/testsuite/ld-elf/provide-hidden-dynabs.nd8
-rw-r--r--ld/testsuite/ld-elf/provide-hidden-dynsec.nd8
-rw-r--r--ld/testsuite/ld-elf/provide-hidden.exp8
-rw-r--r--ld/testsuite/ld-i386/pr23189.d4
-rw-r--r--ld/testsuite/ld-x86-64/pr23189.d4
37 files changed, 173 insertions, 30 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 7233851..0af7a24 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,46 @@
2018-05-21 H.J. Lu <hongjiu.lu@intel.com>
+ PR ld/23201
+ * aout-target.h (MY_bfd_link_hide_symbol): New.
+ * aout-tic30.c (MY_bfd_link_hide_symbol): Likewise.
+ * binary.c (binary_bfd_link_hide_symbol): Likewise.
+ * coff-alpha.c (_bfd_ecoff_bfd_link_hide_symbol): Likewise.
+ * coff-mips.c (_bfd_ecoff_bfd_link_hide_symbol): Likewise.
+ * coff-rs6000.c (_bfd_xcoff_bfd_link_hide_symbol): Likewise.
+ * coffcode.h (coff_bfd_link_hide_symbol): Likewise.
+ * elf-bfd.h (_bfd_elf_link_hide_symbol): Likewise.
+ * elfxx-target.h (bfd_elfNN_bfd_link_hide_symbol): Likewise.
+ * i386msdos.c (msdos_bfd_link_hide_symbol): Likewise.
+ * ihex.c (ihex_bfd_link_hide_symbol): Likewise.
+ * libbfd-in.h (_bfd_nolink_bfd_link_hide_symbol): Likewise.
+ * linker.c (_bfd_generic_link_hide_symbol): Likewise.
+ (bfd_link_hide_symbol): Likewise.
+ * mach-o-target.c (bfd_mach_o_bfd_link_hide_symbol): Likewise.
+ * mmo.c (mmo_bfd_link_hide_symbol): Likewise.
+ * pef.c (bfd_pef_bfd_link_hide_symbol): Likewise.
+ * plugin.c (bfd_plugin_bfd_link_hide_symbol): Likewise.
+ * ppcboot.c (ppcboot_bfd_link_hide_symbol): Likewise.
+ * som.c (som_bfd_link_hide_symbol): Likewise.
+ * srec.c (srec_bfd_link_hide_symbol): Likewise.
+ * tekhex.c (tekhex_bfd_link_hide_symbol): Likewise.
+ * vms-alpha.c (vms_bfd_link_hide_symbol): Likewise.
+ (alpha_vms_bfd_link_hide_symbol): Likewise.
+ * xsym.c (bfd_sym_bfd_link_hide_symbol): Likewise.
+ * coff64-rs6000.c (rs6000_xcoff64_vec): Add
+ _bfd_generic_link_hide_symbol.
+ (rs6000_xcoff64_aix_vec): Likewise.
+ * elflink.c (bfd_elf_record_link_assignment): Don't make forced
+ local symbol dynamic.
+ (_bfd_elf_link_hide_symbol): New function.
+ * elfxx-x86.c (_bfd_x86_elf_link_symbol_references_local): Don't
+ check root.ldscript_def.
+ * targets.c (bfd_target): Add _bfd_link_hide_symbol.
+ (BFD_JUMP_TABLE_LINK): Add NAME##_bfd_link_hide_symbol.
+ * bfd-in2.h: Regenerated.
+ * libbfd.h: Likewise.
+
+2018-05-21 H.J. Lu <hongjiu.lu@intel.com>
+
PR binutils/23199
* elf.c (setup_group): Mark section in a section group with
SHF_GROUP.
diff --git a/bfd/aout-target.h b/bfd/aout-target.h
index f245b1e..9123afc 100644
--- a/bfd/aout-target.h
+++ b/bfd/aout-target.h
@@ -512,6 +512,9 @@ MY_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
#ifndef MY_bfd_define_common_symbol
#define MY_bfd_define_common_symbol bfd_generic_define_common_symbol
#endif
+#ifndef MY_bfd_link_hide_symbol
+#define MY_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
+#endif
#ifndef MY_bfd_define_start_stop
#define MY_bfd_define_start_stop bfd_generic_define_start_stop
#endif
diff --git a/bfd/aout-tic30.c b/bfd/aout-tic30.c
index 31248ec..ddeaaaa 100644
--- a/bfd/aout-tic30.c
+++ b/bfd/aout-tic30.c
@@ -967,6 +967,9 @@ tic30_aout_set_arch_mach (bfd *abfd,
#ifndef MY_bfd_define_common_symbol
#define MY_bfd_define_common_symbol bfd_generic_define_common_symbol
#endif
+#ifndef MY_bfd_link_hide_symbol
+#define MY_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
+#endif
#ifndef MY_bfd_define_start_stop
#define MY_bfd_define_start_stop bfd_generic_define_start_stop
#endif
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index c64eee1..9d643f3 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -7647,6 +7647,7 @@ typedef struct bfd_target
NAME##_bfd_discard_group, \
NAME##_section_already_linked, \
NAME##_bfd_define_common_symbol, \
+ NAME##_bfd_link_hide_symbol, \
NAME##_bfd_define_start_stop
int (*_bfd_sizeof_headers) (bfd *, struct bfd_link_info *);
@@ -7713,6 +7714,10 @@ typedef struct bfd_target
bfd_boolean (*_bfd_define_common_symbol) (bfd *, struct bfd_link_info *,
struct bfd_link_hash_entry *);
+ /* Hide a symbol. */
+ void (*_bfd_link_hide_symbol) (bfd *, struct bfd_link_info *,
+ struct bfd_link_hash_entry *);
+
/* Define a __start, __stop, .startof. or .sizeof. symbol. */
struct bfd_link_hash_entry *
(*_bfd_define_start_stop) (struct bfd_link_info *, const char *,
@@ -7796,6 +7801,13 @@ bfd_boolean bfd_generic_define_common_symbol
#define bfd_define_common_symbol(output_bfd, info, h) \
BFD_SEND (output_bfd, _bfd_define_common_symbol, (output_bfd, info, h))
+void _bfd_generic_link_hide_symbol
+ (bfd *output_bfd, struct bfd_link_info *info,
+ struct bfd_link_hash_entry *h);
+
+#define bfd_link_hide_symbol(output_bfd, info, h) \
+ BFD_SEND (output_bfd, _bfd_link_hide_symbol, (output_bfd, info, h))
+
struct bfd_link_hash_entry *bfd_generic_define_start_stop
(struct bfd_link_info *info,
const char *symbol, asection *sec);
diff --git a/bfd/binary.c b/bfd/binary.c
index 0713f5a..c467b42 100644
--- a/bfd/binary.c
+++ b/bfd/binary.c
@@ -310,6 +310,7 @@ binary_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
#define binary_bfd_discard_group bfd_generic_discard_group
#define binary_section_already_linked _bfd_generic_section_already_linked
#define binary_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define binary_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define binary_bfd_define_start_stop bfd_generic_define_start_stop
#define binary_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
#define binary_bfd_link_just_syms _bfd_generic_link_just_syms
diff --git a/bfd/coff-alpha.c b/bfd/coff-alpha.c
index 0e39f31..699398f 100644
--- a/bfd/coff-alpha.c
+++ b/bfd/coff-alpha.c
@@ -2394,6 +2394,7 @@ static const struct ecoff_backend_data alpha_ecoff_backend_data =
#define _bfd_ecoff_section_already_linked \
_bfd_coff_section_already_linked
#define _bfd_ecoff_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define _bfd_ecoff_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define _bfd_ecoff_bfd_define_start_stop bfd_generic_define_start_stop
#define _bfd_ecoff_bfd_link_check_relocs _bfd_generic_link_check_relocs
diff --git a/bfd/coff-mips.c b/bfd/coff-mips.c
index 3a0163a..d83e10d 100644
--- a/bfd/coff-mips.c
+++ b/bfd/coff-mips.c
@@ -1420,6 +1420,7 @@ static const struct ecoff_backend_data mips_ecoff_backend_data =
#define _bfd_ecoff_section_already_linked \
_bfd_coff_section_already_linked
#define _bfd_ecoff_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define _bfd_ecoff_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define _bfd_ecoff_bfd_define_start_stop bfd_generic_define_start_stop
#define _bfd_ecoff_set_reloc _bfd_generic_set_reloc
diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c
index d8db1f3..053ab18 100644
--- a/bfd/coff-rs6000.c
+++ b/bfd/coff-rs6000.c
@@ -4045,6 +4045,7 @@ const struct xcoff_dwsect_name xcoff_dwsect_names[] = {
#define _bfd_xcoff_bfd_discard_group bfd_generic_discard_group
#define _bfd_xcoff_section_already_linked _bfd_generic_section_already_linked
#define _bfd_xcoff_bfd_define_common_symbol _bfd_xcoff_define_common_symbol
+#define _bfd_xcoff_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define _bfd_xcoff_bfd_define_start_stop bfd_generic_define_start_stop
#define _bfd_xcoff_bfd_link_check_relocs _bfd_generic_link_check_relocs
diff --git a/bfd/coff64-rs6000.c b/bfd/coff64-rs6000.c
index 78f14a0..2135001 100644
--- a/bfd/coff64-rs6000.c
+++ b/bfd/coff64-rs6000.c
@@ -2786,6 +2786,7 @@ const bfd_target rs6000_xcoff64_vec =
bfd_generic_discard_group,
_bfd_generic_section_already_linked,
_bfd_xcoff_define_common_symbol,
+ _bfd_generic_link_hide_symbol,
bfd_generic_define_start_stop,
/* Dynamic */
@@ -3047,6 +3048,7 @@ const bfd_target rs6000_xcoff64_aix_vec =
bfd_generic_discard_group,
_bfd_generic_section_already_linked,
_bfd_xcoff_define_common_symbol,
+ _bfd_generic_link_hide_symbol,
bfd_generic_define_start_stop,
/* Dynamic */
diff --git a/bfd/coffcode.h b/bfd/coffcode.h
index 6ad991c..2ca3205 100644
--- a/bfd/coffcode.h
+++ b/bfd/coffcode.h
@@ -5749,6 +5749,10 @@ static bfd_coff_backend_data bigobj_swap_table =
#define coff_bfd_define_common_symbol bfd_generic_define_common_symbol
#endif
+#ifndef coff_bfd_link_hide_symbol
+#define coff_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
+#endif
+
#ifndef coff_bfd_define_start_stop
#define coff_bfd_define_start_stop bfd_generic_define_start_stop
#endif
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 7b74690..e051c9c 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -2086,6 +2086,8 @@ extern void _bfd_elf_link_hash_copy_indirect
struct elf_link_hash_entry *);
extern void _bfd_elf_link_hash_hide_symbol
(struct bfd_link_info *, struct elf_link_hash_entry *, bfd_boolean);
+extern void _bfd_elf_link_hide_symbol
+ (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *);
extern bfd_boolean _bfd_elf_link_hash_fixup_symbol
(struct bfd_link_info *, struct elf_link_hash_entry *);
extern bfd_boolean _bfd_elf_link_hash_table_init
diff --git a/bfd/elflink.c b/bfd/elflink.c
index ce3765e..0383e4e 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -720,6 +720,7 @@ bfd_elf_record_link_assignment (bfd *output_bfd,
|| h->ref_dynamic
|| bfd_link_dll (info)
|| elf_hash_table (info)->is_relocatable_executable)
+ && !h->forced_local
&& h->dynindx == -1)
{
if (! bfd_elf_link_record_dynamic_symbol (info, h))
@@ -7429,6 +7430,26 @@ _bfd_elf_link_hash_hide_symbol (struct bfd_link_info *info,
}
}
+/* Hide a symbol. */
+
+void
+_bfd_elf_link_hide_symbol (bfd *output_bfd,
+ struct bfd_link_info *info,
+ struct bfd_link_hash_entry *h)
+{
+ if (is_elf_hash_table (info->hash))
+ {
+ const struct elf_backend_data *bed
+ = get_elf_backend_data (output_bfd);
+ struct elf_link_hash_entry *eh
+ = (struct elf_link_hash_entry *) h;
+ bed->elf_backend_hide_symbol (info, eh, TRUE);
+ eh->def_dynamic = 0;
+ eh->ref_dynamic = 0;
+ eh->dynamic_def = 0;
+ }
+}
+
/* Initialize an ELF linker hash table. *TABLE has been zeroed by our
caller. */
diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h
index 89efed3..a86ea58 100644
--- a/bfd/elfxx-target.h
+++ b/bfd/elfxx-target.h
@@ -205,6 +205,10 @@
#define bfd_elfNN_bfd_define_common_symbol bfd_generic_define_common_symbol
#endif
+#ifndef bfd_elfNN_bfd_link_hide_symbol
+#define bfd_elfNN_bfd_link_hide_symbol _bfd_elf_link_hide_symbol
+#endif
+
#ifndef bfd_elfNN_bfd_lookup_section_flags
#define bfd_elfNN_bfd_lookup_section_flags bfd_elf_lookup_section_flags
#endif
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 29d92d2..710417f 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -2047,12 +2047,10 @@ _bfd_x86_elf_link_symbol_references_local (struct bfd_link_info *info,
return TRUE;
}
- /* Symbols created by HIDDEN and PROVIDE_HIDDEN assignments in linker
- script aren't forced local here yet. bfd_hide_sym_by_version
- can't be used to check if a versioned symbol is hidden. It has to
- be syncd with _bfd_elf_link_assign_sym_version to get the correct
- answer. */
- if (!h->root.ldscript_def && h->versioned == unversioned)
+ /* bfd_hide_sym_by_version can't be used to check if a versioned symbol
+ is hidden. It has to be syncd with _bfd_elf_link_assign_sym_version
+ to get the correct answer. */
+ if (h->versioned == unversioned)
eh->local_ref = 1;
return FALSE;
diff --git a/bfd/i386msdos.c b/bfd/i386msdos.c
index a47acf4..77e9880 100644
--- a/bfd/i386msdos.c
+++ b/bfd/i386msdos.c
@@ -230,6 +230,7 @@ msdos_set_section_contents (bfd *abfd,
#define msdos_section_already_linked \
_bfd_generic_section_already_linked
#define msdos_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define msdos_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define msdos_bfd_define_start_stop bfd_generic_define_start_stop
#define msdos_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
#define msdos_bfd_link_add_symbols _bfd_generic_link_add_symbols
diff --git a/bfd/ihex.c b/bfd/ihex.c
index 096c19c..80bcbe9 100644
--- a/bfd/ihex.c
+++ b/bfd/ihex.c
@@ -943,6 +943,7 @@ ihex_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
#define ihex_bfd_discard_group bfd_generic_discard_group
#define ihex_section_already_linked _bfd_generic_section_already_linked
#define ihex_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define ihex_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define ihex_bfd_define_start_stop bfd_generic_define_start_stop
#define ihex_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
#define ihex_bfd_link_add_symbols _bfd_generic_link_add_symbols
diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h
index bb3cf48..9796f2d 100644
--- a/bfd/libbfd-in.h
+++ b/bfd/libbfd-in.h
@@ -534,6 +534,8 @@ extern bfd_boolean _bfd_nolink_section_already_linked
extern bfd_boolean _bfd_nolink_bfd_define_common_symbol
(bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *)
ATTRIBUTE_HIDDEN;
+#define _bfd_nolink_bfd_link_hide_symbol \
+ _bfd_generic_link_hide_symbol
extern struct bfd_link_hash_entry *_bfd_nolink_bfd_define_start_stop
(struct bfd_link_info *, const char *, asection *) ATTRIBUTE_HIDDEN;
#define _bfd_nolink_bfd_link_check_relocs \
diff --git a/bfd/libbfd.h b/bfd/libbfd.h
index b810c40..f357e0e 100644
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -539,6 +539,8 @@ extern bfd_boolean _bfd_nolink_section_already_linked
extern bfd_boolean _bfd_nolink_bfd_define_common_symbol
(bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *)
ATTRIBUTE_HIDDEN;
+#define _bfd_nolink_bfd_link_hide_symbol \
+ _bfd_generic_link_hide_symbol
extern struct bfd_link_hash_entry *_bfd_nolink_bfd_define_start_stop
(struct bfd_link_info *, const char *, asection *) ATTRIBUTE_HIDDEN;
#define _bfd_nolink_bfd_link_check_relocs \
diff --git a/bfd/linker.c b/bfd/linker.c
index 3019919..6b4c8e5 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -3112,6 +3112,32 @@ bfd_generic_define_common_symbol (bfd *output_bfd,
/*
FUNCTION
+ _bfd_generic_link_hide_symbol
+
+SYNOPSIS
+ void _bfd_generic_link_hide_symbol
+ (bfd *output_bfd, struct bfd_link_info *info,
+ struct bfd_link_hash_entry *h);
+
+DESCRIPTION
+ Hide symbol @var{h}.
+ This is an internal function. It should not be called from
+ outside the BFD library.
+
+.#define bfd_link_hide_symbol(output_bfd, info, h) \
+. BFD_SEND (output_bfd, _bfd_link_hide_symbol, (output_bfd, info, h))
+.
+*/
+
+void
+_bfd_generic_link_hide_symbol (bfd *output_bfd ATTRIBUTE_UNUSED,
+ struct bfd_link_info *info ATTRIBUTE_UNUSED,
+ struct bfd_link_hash_entry *h ATTRIBUTE_UNUSED)
+{
+}
+
+/*
+FUNCTION
bfd_generic_define_start_stop
SYNOPSIS
diff --git a/bfd/mach-o-target.c b/bfd/mach-o-target.c
index 8859b23..9f3b487 100644
--- a/bfd/mach-o-target.c
+++ b/bfd/mach-o-target.c
@@ -55,6 +55,7 @@
#define bfd_mach_o_bfd_discard_group bfd_generic_discard_group
#define bfd_mach_o_section_already_linked _bfd_generic_section_already_linked
#define bfd_mach_o_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define bfd_mach_o_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define bfd_mach_o_bfd_define_start_stop bfd_generic_define_start_stop
#define bfd_mach_o_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
#define bfd_mach_o_core_file_matches_executable_p generic_core_file_matches_executable_p
diff --git a/bfd/mmo.c b/bfd/mmo.c
index 4b969c2..6a3e255 100644
--- a/bfd/mmo.c
+++ b/bfd/mmo.c
@@ -3318,6 +3318,7 @@ mmo_write_object_contents (bfd *abfd)
#define mmo_section_already_linked \
_bfd_generic_section_already_linked
#define mmo_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define mmo_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define mmo_bfd_define_start_stop bfd_generic_define_start_stop
/* We want to copy time of creation, otherwise we'd use
diff --git a/bfd/pef.c b/bfd/pef.c
index a55ca06..5746b96 100644
--- a/bfd/pef.c
+++ b/bfd/pef.c
@@ -59,6 +59,7 @@
#define bfd_pef_bfd_discard_group bfd_generic_discard_group
#define bfd_pef_section_already_linked _bfd_generic_section_already_linked
#define bfd_pef_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define bfd_pef_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define bfd_pef_bfd_define_start_stop bfd_generic_define_start_stop
#define bfd_pef_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
#define bfd_pef_bfd_link_add_symbols _bfd_generic_link_add_symbols
diff --git a/bfd/plugin.c b/bfd/plugin.c
index a2c1bd5..16a706a 100644
--- a/bfd/plugin.c
+++ b/bfd/plugin.c
@@ -105,6 +105,7 @@ dlerror (void)
#define bfd_plugin_bfd_discard_group bfd_generic_discard_group
#define bfd_plugin_section_already_linked _bfd_generic_section_already_linked
#define bfd_plugin_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define bfd_plugin_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define bfd_plugin_bfd_define_start_stop bfd_generic_define_start_stop
#define bfd_plugin_bfd_copy_link_hash_symbol_type _bfd_generic_copy_link_hash_symbol_type
#define bfd_plugin_bfd_link_check_relocs _bfd_generic_link_check_relocs
diff --git a/bfd/ppcboot.c b/bfd/ppcboot.c
index bbb2cc7..0d92fd1 100644
--- a/bfd/ppcboot.c
+++ b/bfd/ppcboot.c
@@ -460,6 +460,7 @@ ppcboot_bfd_print_private_bfd_data (bfd *abfd, void * farg)
#define ppcboot_section_already_linked \
_bfd_generic_section_already_linked
#define ppcboot_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define ppcboot_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define ppcboot_bfd_define_start_stop bfd_generic_define_start_stop
#define ppcboot_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
#define ppcboot_bfd_link_add_symbols _bfd_generic_link_add_symbols
diff --git a/bfd/som.c b/bfd/som.c
index 6220df7..d2bdc6f 100644
--- a/bfd/som.c
+++ b/bfd/som.c
@@ -6759,6 +6759,7 @@ som_bfd_link_split_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
#define som_bfd_discard_group bfd_generic_discard_group
#define som_section_already_linked _bfd_generic_section_already_linked
#define som_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define som_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define som_bfd_define_start_stop bfd_generic_define_start_stop
#define som_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
#define som_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
diff --git a/bfd/srec.c b/bfd/srec.c
index 4996109..66cc72f 100644
--- a/bfd/srec.c
+++ b/bfd/srec.c
@@ -1278,6 +1278,7 @@ srec_print_symbol (bfd *abfd,
#define srec_bfd_discard_group bfd_generic_discard_group
#define srec_section_already_linked _bfd_generic_section_already_linked
#define srec_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define srec_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define srec_bfd_define_start_stop bfd_generic_define_start_stop
#define srec_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
#define srec_bfd_link_add_symbols _bfd_generic_link_add_symbols
diff --git a/bfd/targets.c b/bfd/targets.c
index 5a2a684..531703d 100644
--- a/bfd/targets.c
+++ b/bfd/targets.c
@@ -465,6 +465,7 @@ BFD_JUMP_TABLE macros.
. NAME##_bfd_discard_group, \
. NAME##_section_already_linked, \
. NAME##_bfd_define_common_symbol, \
+. NAME##_bfd_link_hide_symbol, \
. NAME##_bfd_define_start_stop
.
. int (*_bfd_sizeof_headers) (bfd *, struct bfd_link_info *);
@@ -531,6 +532,10 @@ BFD_JUMP_TABLE macros.
. bfd_boolean (*_bfd_define_common_symbol) (bfd *, struct bfd_link_info *,
. struct bfd_link_hash_entry *);
.
+. {* Hide a symbol. *}
+. void (*_bfd_link_hide_symbol) (bfd *, struct bfd_link_info *,
+. struct bfd_link_hash_entry *);
+.
. {* Define a __start, __stop, .startof. or .sizeof. symbol. *}
. struct bfd_link_hash_entry *
. (*_bfd_define_start_stop) (struct bfd_link_info *, const char *,
diff --git a/bfd/tekhex.c b/bfd/tekhex.c
index 6a00c9f..893d06d 100644
--- a/bfd/tekhex.c
+++ b/bfd/tekhex.c
@@ -981,6 +981,7 @@ tekhex_print_symbol (bfd *abfd,
#define tekhex_bfd_discard_group bfd_generic_discard_group
#define tekhex_section_already_linked _bfd_generic_section_already_linked
#define tekhex_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define tekhex_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define tekhex_bfd_define_start_stop bfd_generic_define_start_stop
#define tekhex_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
#define tekhex_bfd_link_add_symbols _bfd_generic_link_add_symbols
diff --git a/bfd/vms-alpha.c b/bfd/vms-alpha.c
index b52f580..11817cfb 100644
--- a/bfd/vms-alpha.c
+++ b/bfd/vms-alpha.c
@@ -9498,6 +9498,7 @@ bfd_vms_get_data (bfd *abfd)
#define vms_bfd_discard_group bfd_generic_discard_group
#define vms_section_already_linked _bfd_generic_section_already_linked
#define vms_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define vms_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define vms_bfd_define_start_stop bfd_generic_define_start_stop
#define vms_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
@@ -9545,6 +9546,7 @@ bfd_vms_get_data (bfd *abfd)
_bfd_generic_section_already_linked
#define alpha_vms_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define alpha_vms_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define alpha_vms_bfd_define_start_stop bfd_generic_define_start_stop
#define alpha_vms_bfd_link_just_syms _bfd_generic_link_just_syms
#define alpha_vms_bfd_copy_link_hash_symbol_type \
diff --git a/bfd/xsym.c b/bfd/xsym.c
index 8ea0e7e..56607f0 100644
--- a/bfd/xsym.c
+++ b/bfd/xsym.c
@@ -51,6 +51,7 @@
#define bfd_sym_bfd_discard_group bfd_generic_discard_group
#define bfd_sym_section_already_linked _bfd_generic_section_already_linked
#define bfd_sym_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define bfd_sym_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
#define bfd_sym_bfd_define_start_stop bfd_generic_define_start_stop
#define bfd_sym_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
#define bfd_sym_bfd_link_add_symbols _bfd_generic_link_add_symbols
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 15de953..0e03d08 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,17 @@
+2018-05-21 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/23201
+ * ldexp.c (exp_fold_tree_1): Call bfd_link_hide_symbol to hide
+ a symbol.
+ * testsuite/ld-elf/provide-hidden-dynabs.nd: Removed.
+ * testsuite/ld-elf/provide-hidden-dynsec.nd: Likewise.
+ * testsuite/ld-elf/provide-hidden.exp: Replace
+ provide-hidden-dynsec.nd with provide-hidden-sec.nd and
+ provide-hidden-dyn.nd. Replace provide-hidden-dynabs.nd with
+ provide-hidden-abs.nd and provide-hidden-dyn.nd.
+ * testsuite/ld-i386/pr23189.d: Expect no dynamic relocation.
+ * testsuite/ld-x86-64/pr23189.d: Likewise.
+
2018-05-18 H.J. Lu <hongjiu.lu@intel.com>
PR ld/23194
diff --git a/ld/ldexp.c b/ld/ldexp.c
index f9dc362..6fa251e 100644
--- a/ld/ldexp.c
+++ b/ld/ldexp.c
@@ -1200,6 +1200,9 @@ exp_fold_tree_1 (etree_type *tree)
h->u.def.section = expld.result.section;
h->linker_def = ! tree->assign.type.lineno;
h->ldscript_def = 1;
+ if (tree->assign.hidden)
+ bfd_link_hide_symbol (link_info.output_bfd,
+ &link_info, h);
/* Copy the symbol type if this is an expression only
referencing a single symbol. (If the expression
diff --git a/ld/testsuite/ld-elf/provide-hidden-dynabs.nd b/ld/testsuite/ld-elf/provide-hidden-dynabs.nd
deleted file mode 100644
index 86e3adc..0000000
--- a/ld/testsuite/ld-elf/provide-hidden-dynabs.nd
+++ /dev/null
@@ -1,8 +0,0 @@
-Symbol table '\.dynsym' contains [0-9]+ entries:
-#...
- *[0-9]+: 0*23400000 +0 (?:NOTYPE|OBJECT) +LOCAL +DEFAULT +ABS foo
-#...
-Symbol table '\.symtab' contains [0-9]+ entries:
-#...
- *[0-9]+: 0*23400000 +0 (?:NOTYPE|OBJECT) +LOCAL +DEFAULT +ABS foo
-#pass
diff --git a/ld/testsuite/ld-elf/provide-hidden-dynsec.nd b/ld/testsuite/ld-elf/provide-hidden-dynsec.nd
deleted file mode 100644
index 716dfa1..0000000
--- a/ld/testsuite/ld-elf/provide-hidden-dynsec.nd
+++ /dev/null
@@ -1,8 +0,0 @@
-Symbol table '\.dynsym' contains [0-9]+ entries:
-#...
- *[0-9]+: 0*23400000 +0 (?:NOTYPE|OBJECT) +LOCAL +DEFAULT +[0-9]+ foo
-#...
-Symbol table '\.symtab' contains [0-9]+ entries:
-#...
- *[0-9]+: 0*23400000 +0 (?:NOTYPE|OBJECT) +LOCAL +DEFAULT +[0-9]+ foo
-#pass
diff --git a/ld/testsuite/ld-elf/provide-hidden.exp b/ld/testsuite/ld-elf/provide-hidden.exp
index 1fc4e61..4b72134 100644
--- a/ld/testsuite/ld-elf/provide-hidden.exp
+++ b/ld/testsuite/ld-elf/provide-hidden.exp
@@ -86,7 +86,9 @@ run_ld_link_tests [list \
"$LFLAGS -T provide-hidden-1.ld" "tmpdir/provide-hidden-s.so" \
"" \
[list provide-hidden-3.s] \
- [list "readelf -s provide-hidden-dynsec.nd"] \
+ [list \
+ [list readelf -s provide-hidden-sec.nd] \
+ [list readelf -s provide-hidden-dyn.nd]] \
"provide-hidden-4"] \
[list \
"$testname 5" \
@@ -138,7 +140,9 @@ run_ld_link_tests [list \
"$LFLAGS -T provide-hidden-2.ld" "tmpdir/provide-hidden-s.so" \
"" \
[list provide-hidden-3.s] \
- [list "readelf -s provide-hidden-dynabs.nd"] \
+ [list \
+ [list readelf -s provide-hidden-abs.nd] \
+ [list readelf -s provide-hidden-dyn.nd]] \
"provide-hidden-10"] \
[list \
"$testname 11" \
diff --git a/ld/testsuite/ld-i386/pr23189.d b/ld/testsuite/ld-i386/pr23189.d
index 9345b42..d388830 100644
--- a/ld/testsuite/ld-i386/pr23189.d
+++ b/ld/testsuite/ld-i386/pr23189.d
@@ -2,6 +2,4 @@
#ld: -shared -melf_i386 -T pr23189.t
#readelf: -r --wide
-Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
- Offset Info Type Sym. Value Symbol's Name
-[0-9a-f]+ +[0-9a-f]+ +R_386_RELATIVE +
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-x86-64/pr23189.d b/ld/testsuite/ld-x86-64/pr23189.d
index 7951c7a..6fc4b7e 100644
--- a/ld/testsuite/ld-x86-64/pr23189.d
+++ b/ld/testsuite/ld-x86-64/pr23189.d
@@ -2,6 +2,4 @@
#ld: -shared -melf_x86_64 -T pr23189.t
#readelf: -r --wide
-Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
- Offset Info Type Symbol's Value Symbol's Name \+ Addend
-[0-9a-f]+ +[0-9a-f]+ +R_X86_64_RELATIVE +[0-9a-f]+
+There are no relocations in this file.