* [PATCH] ld: Downgrade -z defs errors to warnings if --warn-unsolved-symbols
@ 2020-04-10 20:37 Fangrui Song
0 siblings, 0 replies; only message in thread
From: Fangrui Song @ 2020-04-10 20:37 UTC (permalink / raw)
To: binutils; +Cc: Fangrui Song
This cleans up the interface and makes -z defs synonymous with
--no-undefined.
---
bfd/ChangeLog | 16 ++++++++++++++++
bfd/coff-rs6000.c | 3 ++-
bfd/coff64-rs6000.c | 9 +++++----
bfd/elf-bfd.h | 5 +++--
bfd/elf32-m32r.c | 12 ++++++------
bfd/elf32-score.c | 15 ++++++++-------
bfd/elf32-score7.c | 13 +++++++------
bfd/elf32-sh.c | 13 +++++++------
bfd/elf32-spu.c | 5 +++--
bfd/elf64-hppa.c | 5 +++--
bfd/elflink.c | 10 +++++-----
bfd/elfxx-mips.c | 7 ++++---
include/ChangeLog | 7 +++++++
include/bfdlink.h | 6 ++++--
ld/ChangeLog | 9 +++++++++
ld/emultempl/aix.em | 4 ++--
ld/emultempl/elf.em | 6 +++---
ld/lexsup.c | 36 ++++++++++--------------------------
18 files changed, 104 insertions(+), 77 deletions(-)
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 120fb38646..429dedc007 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,19 @@
+2020-04-10 Fangrui Song <maskray@google.com>
+
+ PR binutils/24613
+ * coff-rs6000.c (xcoff_ppc_relocate_section): Change RM_GENERATE_ERROR
+ to RM_DIAGNOSE plus a check of warn_unresolved_syms.
+ * coff64-rs6000.c (xcoff_ppc_relocate_section): Likewise.
+ * elf-bfd.h (_bfd_elf_large_com_section): Likewise.
+ * elf32-m32r.c (m32r_elf_relocate_section): Likewise.
+ * elf32-score.c (s3_bfd_score_elf_relocate_section): Likewise.
+ * elf32-score7.c (s7_bfd_score_elf_relocate_section): Likewise.
+ * elf32-sh.c (sh_elf_relocate_section): Likewise.
+ * elf32-spu.c (spu_elf_relocate_section): Likewise.
+ * elf64-hppa.c (elf64_hppa_relocate_section): Likewise.
+ * elflink.c (elf_link_output_extsym): Likewise.
+ * elfxx-mips.c (mips_elf_calculate_relocation): Likewise.
+
2020-04-07 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Nick Clifton <nickc@redhat.com>
diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c
index bf87596a4f..51fab9f053 100644
--- a/bfd/coff-rs6000.c
+++ b/bfd/coff-rs6000.c
@@ -3389,7 +3389,8 @@ xcoff_ppc_relocate_section (bfd *output_bfd,
(info, h->root.root.string,
input_bfd, input_section,
rel->r_vaddr - input_section->vma,
- info->unresolved_syms_in_objects == RM_GENERATE_ERROR);
+ info->unresolved_syms_in_objects == RM_DIAGNOSE &&
+ !info->warn_unresolved_syms);
if (h->root.type == bfd_link_hash_defined
|| h->root.type == bfd_link_hash_defweak)
diff --git a/bfd/coff64-rs6000.c b/bfd/coff64-rs6000.c
index d34e25903c..dce1395cfc 100644
--- a/bfd/coff64-rs6000.c
+++ b/bfd/coff64-rs6000.c
@@ -1249,10 +1249,11 @@ xcoff64_ppc_relocate_section (bfd *output_bfd,
{
if (info->unresolved_syms_in_objects != RM_IGNORE
&& (h->flags & XCOFF_WAS_UNDEFINED) != 0)
- (*info->callbacks->undefined_symbol)
- (info, h->root.root.string, input_bfd, input_section,
- rel->r_vaddr - input_section->vma,
- info->unresolved_syms_in_objects == RM_GENERATE_ERROR);
+ (*info->callbacks->undefined_symbol) (
+ info, h->root.root.string, input_bfd, input_section,
+ rel->r_vaddr - input_section->vma,
+ info->unresolved_syms_in_objects == RM_DIAGNOSE
+ && !info->warn_unresolved_syms);
if (h->root.type == bfd_link_hash_defined
|| h->root.type == bfd_link_hash_defweak)
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 03e2b6fe85..b08502cd1c 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -2930,8 +2930,9 @@ extern asection _bfd_elf_large_com_section;
else if (!bfd_link_relocatable (info)) \
{ \
bfd_boolean err; \
- err = (info->unresolved_syms_in_objects == RM_GENERATE_ERROR \
- || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT); \
+ err = (info->unresolved_syms_in_objects == RM_DIAGNOSE && \
+ !info->warn_unresolved_syms) \
+ || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT; \
(*info->callbacks->undefined_symbol) (info, \
h->root.root.string, \
input_bfd, \
diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c
index 2a4b0b2ebe..39dd83a722 100644
--- a/bfd/elf32-m32r.c
+++ b/bfd/elf32-m32r.c
@@ -2551,12 +2551,12 @@ m32r_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
&& ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
;
else if (!bfd_link_relocatable (info))
- (*info->callbacks->undefined_symbol)
- (info, h->root.root.string, input_bfd,
- input_section, offset,
- (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
- || ELF_ST_VISIBILITY (h->other)));
- }
+ (*info->callbacks->undefined_symbol) (
+ info, h->root.root.string, input_bfd, input_section, offset,
+ (info->unresolved_syms_in_objects == RM_DIAGNOSE
+ && !info->warn_unresolved_syms)
+ || ELF_ST_VISIBILITY (h->other));
+ }
if (sec != NULL && discarded_section (sec))
RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
diff --git a/bfd/elf32-score.c b/bfd/elf32-score.c
index 8c2e3042ae..9d0afa3dbc 100644
--- a/bfd/elf32-score.c
+++ b/bfd/elf32-score.c
@@ -2669,13 +2669,14 @@ s3_bfd_score_elf_relocate_section (bfd *output_bfd,
}
else if (!bfd_link_relocatable (info))
{
- (*info->callbacks->undefined_symbol)
- (info, h->root.root.root.string, input_bfd,
- input_section, rel->r_offset,
- (info->unresolved_syms_in_objects == RM_GENERATE_ERROR)
- || ELF_ST_VISIBILITY (h->root.other));
- relocation = 0;
- }
+ (*info->callbacks->undefined_symbol) (
+ info, h->root.root.root.string, input_bfd, input_section,
+ rel->r_offset,
+ (info->unresolved_syms_in_objects == RM_DIAGNOSE
+ && !info->warn_unresolved_syms)
+ || ELF_ST_VISIBILITY (h->root.other));
+ relocation = 0;
+ }
}
if (sec != NULL && discarded_section (sec))
diff --git a/bfd/elf32-score7.c b/bfd/elf32-score7.c
index 752796c45b..63b3d21110 100644
--- a/bfd/elf32-score7.c
+++ b/bfd/elf32-score7.c
@@ -2443,12 +2443,13 @@ s7_bfd_score_elf_relocate_section (bfd *output_bfd,
}
else if (!bfd_link_relocatable (info))
{
- (*info->callbacks->undefined_symbol)
- (info, h->root.root.root.string, input_bfd,
- input_section, rel->r_offset,
- (info->unresolved_syms_in_objects == RM_GENERATE_ERROR)
- || ELF_ST_VISIBILITY (h->root.other));
- relocation = 0;
+ (*info->callbacks->undefined_symbol) (
+ info, h->root.root.root.string, input_bfd, input_section,
+ rel->r_offset,
+ (info->unresolved_syms_in_objects == RM_DIAGNOSE
+ && !info->warn_unresolved_syms)
+ || ELF_ST_VISIBILITY (h->root.other));
+ relocation = 0;
}
}
diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
index 9a00bde1d9..416676393c 100644
--- a/bfd/elf32-sh.c
+++ b/bfd/elf32-sh.c
@@ -3815,12 +3815,13 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
&& ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
;
else if (!bfd_link_relocatable (info))
- (*info->callbacks->undefined_symbol)
- (info, h->root.root.string, input_bfd,
- input_section, rel->r_offset,
- (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
- || ELF_ST_VISIBILITY (h->other)));
- }
+ (*info->callbacks->undefined_symbol) (
+ info, h->root.root.string, input_bfd, input_section,
+ rel->r_offset,
+ (info->unresolved_syms_in_objects == RM_DIAGNOSE
+ && !info->warn_unresolved_syms)
+ || ELF_ST_VISIBILITY (h->other));
+ }
if (sec != NULL && discarded_section (sec))
RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c
index 711537d3de..8d3ec64793 100644
--- a/bfd/elf32-spu.c
+++ b/bfd/elf32-spu.c
@@ -4927,8 +4927,9 @@ spu_elf_relocate_section (bfd *output_bfd,
&& !(r_type == R_SPU_PPU32 || r_type == R_SPU_PPU64))
{
bfd_boolean err;
- err = (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
- || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT);
+ err = (info->unresolved_syms_in_objects == RM_DIAGNOSE &&
+ !info->warn_unresolved_syms)
+ || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT;
(*info->callbacks->undefined_symbol) (info,
h->root.root.string,
input_bfd,
diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c
index a2602daf2b..42b03096ec 100644
--- a/bfd/elf64-hppa.c
+++ b/bfd/elf64-hppa.c
@@ -3882,8 +3882,9 @@ elf64_hppa_relocate_section (bfd *output_bfd,
else if (!bfd_link_relocatable (info))
{
bfd_boolean err;
- err = (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
- || ELF_ST_VISIBILITY (eh->other) != STV_DEFAULT);
+ err = (info->unresolved_syms_in_objects == RM_DIAGNOSE &&
+ !info->warn_unresolved_syms)
+ || ELF_ST_VISIBILITY (eh->other) != STV_DEFAULT;
(*info->callbacks->undefined_symbol) (info,
eh->root.root.string,
input_bfd,
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 7c0849423a..3847361284 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -9886,11 +9886,11 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
&& (!h->ref_regular || flinfo->info->gc_sections)
&& !elf_link_check_versioned_symbol (flinfo->info, bed, h)
&& flinfo->info->unresolved_syms_in_shared_libs != RM_IGNORE)
- (*flinfo->info->callbacks->undefined_symbol)
- (flinfo->info, h->root.root.string,
- h->ref_regular ? NULL : h->root.u.undef.abfd,
- NULL, 0,
- flinfo->info->unresolved_syms_in_shared_libs == RM_GENERATE_ERROR);
+ (*flinfo->info->callbacks->undefined_symbol) (
+ flinfo->info, h->root.root.string,
+ h->ref_regular ? NULL : h->root.u.undef.abfd, NULL, 0,
+ flinfo->info->unresolved_syms_in_shared_libs == RM_DIAGNOSE
+ && !flinfo->info->warn_unresolved_syms);
/* Strip a global symbol defined in a discarded section. */
if (h->indx == -3)
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 4671b50449..633004be18 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -5649,9 +5649,10 @@ mips_elf_calculate_relocation (bfd *abfd, bfd *input_bfd,
}
else
{
- bfd_boolean reject_undefined
- = (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
- || ELF_ST_VISIBILITY (h->root.other) != STV_DEFAULT);
+ bfd_boolean reject_undefined
+ = (info->unresolved_syms_in_objects == RM_DIAGNOSE
+ && !info->warn_unresolved_syms)
+ || ELF_ST_VISIBILITY (h->root.other) != STV_DEFAULT;
(*info->callbacks->undefined_symbol)
(info, h->root.root.root.string, input_bfd,
diff --git a/include/ChangeLog b/include/ChangeLog
index 7964db299b..63da3da516 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,10 @@
+2020-04-10 Fangrui Song <maskray@google.com>
+
+ PR binutils/24613
+ * bfdlink.h (enum report_method): Delete RM_GENERATE_WARNING and
+ RM_GENERATE_ERROR. Add RM_DIAGNOSE.
+ (struct bfd_link_info): Add warn_unresolved_syms.
+
2020-04-02 Jan W. Jagersma <jwjagersma@gmail.com>
* coff/go32exe.h: Remove file.
diff --git a/include/bfdlink.h b/include/bfdlink.h
index 84b9dd7a0a..3822bc3f40 100644
--- a/include/bfdlink.h
+++ b/include/bfdlink.h
@@ -270,8 +270,7 @@ enum report_method
allowed to set the value. */
RM_NOT_YET_SET = 0,
RM_IGNORE,
- RM_GENERATE_WARNING,
- RM_GENERATE_ERROR
+ RM_DIAGNOSE,
};
typedef enum {with_flags, without_flags} flag_type;
@@ -387,6 +386,9 @@ struct bfd_link_info
The same defaults apply. */
ENUM_BITFIELD (report_method) unresolved_syms_in_shared_libs : 2;
+ /* TRUE if unresolved symbols are to be warned, rather than errored. */
+ unsigned int warn_unresolved_syms: 1;
+
/* TRUE if shared objects should be linked directly, not shared. */
unsigned int static_link: 1;
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 06e7f5de2a..2bc4854228 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,12 @@
+2020-04-10 Fangrui Song <maskray@google.com>
+
+ PR binutils/24613
+ * lexsup.c (parse_args): Change RM_GENERATE_WARNING and
+ RM_GENERATE_ERROR to RM_DIAGNOSE.
+ * emultempl/aix.em (ld_${EMULATION_NAME}_emulation): Change
+ RM_GENERATE_ERROR to RM_DIAGNOSE.
+ * emultempl/elf.em (ld_${EMULATION_NAME}_emulation): Likewise.
+
2020-04-10 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
* testsuite/ld-shared/shared.exp: Remove dangling comments.
diff --git a/ld/emultempl/aix.em b/ld/emultempl/aix.em
index 2da3870989..5b73c3e7e5 100644
--- a/ld/emultempl/aix.em
+++ b/ld/emultempl/aix.em
@@ -472,8 +472,8 @@ gld${EMULATION_NAME}_handle_option (int optc)
break;
case OPTION_ERNOTOK:
- link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
- link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
+ link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
+ link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
break;
case OPTION_EROK:
diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
index bb7e537530..899030016c 100644
--- a/ld/emultempl/elf.em
+++ b/ld/emultempl/elf.em
@@ -675,8 +675,8 @@ fragment <<EOF
case OPTION_GROUP:
link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
/* Groups must be self-contained. */
- link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
- link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
+ link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
+ link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
break;
case OPTION_EXCLUDE_LIBS:
@@ -704,7 +704,7 @@ fi
fragment <<EOF
case 'z':
if (strcmp (optarg, "defs") == 0)
- link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
+ link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
else if (strcmp (optarg, "undefs") == 0)
link_info.unresolved_syms_in_objects = RM_IGNORE;
else if (strcmp (optarg, "muldefs") == 0)
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 2597e2d630..984e4eaae0 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -569,7 +569,6 @@ parse_args (unsigned argc, char **argv)
struct option *longopts;
struct option *really_longopts;
int last_optind;
- enum report_method how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
enum symbolic_enum
{
symbolic_unset = 0,
@@ -957,15 +956,13 @@ parse_args (unsigned argc, char **argv)
link_info.keep_memory = FALSE;
break;
case OPTION_NO_UNDEFINED:
- link_info.unresolved_syms_in_objects
- = how_to_report_unresolved_symbols;
+ link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
break;
case OPTION_ALLOW_SHLIB_UNDEFINED:
link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
break;
case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
- link_info.unresolved_syms_in_shared_libs
- = how_to_report_unresolved_symbols;
+ link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
break;
case OPTION_UNRESOLVED_SYMBOLS:
if (strcmp (optarg, "ignore-all") == 0)
@@ -975,40 +972,27 @@ parse_args (unsigned argc, char **argv)
}
else if (strcmp (optarg, "report-all") == 0)
{
- link_info.unresolved_syms_in_objects
- = how_to_report_unresolved_symbols;
- link_info.unresolved_syms_in_shared_libs
- = how_to_report_unresolved_symbols;
+ link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
+ link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
}
else if (strcmp (optarg, "ignore-in-object-files") == 0)
{
link_info.unresolved_syms_in_objects = RM_IGNORE;
- link_info.unresolved_syms_in_shared_libs
- = how_to_report_unresolved_symbols;
+ link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
}
else if (strcmp (optarg, "ignore-in-shared-libs") == 0)
{
- link_info.unresolved_syms_in_objects
- = how_to_report_unresolved_symbols;
+ link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
}
else
einfo (_("%F%P: bad --unresolved-symbols option: %s\n"), optarg);
break;
case OPTION_WARN_UNRESOLVED_SYMBOLS:
- how_to_report_unresolved_symbols = RM_GENERATE_WARNING;
- if (link_info.unresolved_syms_in_objects == RM_GENERATE_ERROR)
- link_info.unresolved_syms_in_objects = RM_GENERATE_WARNING;
- if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)
- link_info.unresolved_syms_in_shared_libs = RM_GENERATE_WARNING;
+ link_info.warn_unresolved_syms = TRUE;
break;
-
case OPTION_ERROR_UNRESOLVED_SYMBOLS:
- how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
- if (link_info.unresolved_syms_in_objects == RM_GENERATE_WARNING)
- link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
- if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_WARNING)
- link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
+ link_info.warn_unresolved_syms = FALSE;
break;
case OPTION_ALLOW_MULTIPLE_DEFINITION:
link_info.allow_multiple_definition = TRUE;
@@ -1638,11 +1622,11 @@ parse_args (unsigned argc, char **argv)
if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
/* FIXME: Should we allow emulations a chance to set this ? */
- link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols;
+ link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
/* FIXME: Should we allow emulations a chance to set this ? */
- link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols;
+ link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
if (bfd_link_relocatable (&link_info)
&& command_line.check_section_addresses < 0)
--
2.26.0.110.g2183baf09c-goog
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-04-10 20:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-10 20:37 [PATCH] ld: Downgrade -z defs errors to warnings if --warn-unsolved-symbols Fangrui Song
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).