From a100d66fb42044153dc0e93c96d7944dab0cc674 Mon Sep 17 00:00:00 2001 From: Sriraman Tallam Date: Thu, 23 Apr 2015 13:56:40 -0700 Subject: Add option --weak-unresolved-symbols to treat unresolved symbols as weak ref. This patch adds option --weak-unresolved-symbols to treat unresolved symbols as weak references. This is helpful when we want the link to succeed with unresolved symbols and the dynamic loader to not complain at run-time. Option --warn-unresolved-symbols lets the link succeed but could fail at run-time with unresolved symbol warnings especially when the unresolved symbols have GOT entries and dynamic relocations against them, like when -fPIE is used. --- gold/symtab.cc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gold/symtab.cc') diff --git a/gold/symtab.cc b/gold/symtab.cc index c197221..d2ed352 100644 --- a/gold/symtab.cc +++ b/gold/symtab.cc @@ -2920,6 +2920,13 @@ Symbol_table::sized_write_globals(const Stringpool* sympool, typename elfcpp::Elf_types::Elf_Addr dynsym_value = sym_value; elfcpp::STB binding = sym->binding(); + // If --weak-unresolved-symbols is set, change binding of unresolved + // global symbols to STB_WEAK. + if (parameters->options().weak_unresolved_symbols() + && binding == elfcpp::STB_GLOBAL + && sym->is_undefined()) + binding = elfcpp::STB_WEAK; + // If --no-gnu-unique is set, change STB_GNU_UNIQUE to STB_GLOBAL. if (binding == elfcpp::STB_GNU_UNIQUE && !parameters->options().gnu_unique()) -- cgit v1.1