gold: Always resolve non-default weak undefined to 0

Non-default weak undefined symbols in executable and shared library are
always resolved to 0 at runtime and don't need dynamic relocation.

Tested on i686, x86-64, powerpc64le and aarch64.

	PR gold/32071
	* symtab.cc (Symbol::final_value_is_known): Always resolve
	non-default weak undefined symbol in executable and shared library
	to 0 at runtime.
	* symtab.h (Symbol::needs_dynamic_reloc): Return false for
	non-default weak undefined symbol in executable and shared library.
	* testsuite/Makefile.am: Add weak_undef_test_3 and
	weak_undef_test_4 tests.
	* testsuite/Makefile.in: Regenerated.
	* testsuite/weak_undef_lib_4.c: New file.
	* testsuite/weak_undef_test_3.c: Likewise.
	* testsuite/weak_undef_test_4.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
This commit is contained in:
H.J. Lu 2024-08-21 08:06:41 -07:00
parent 1a86b364a3
commit 229ecf80f3
7 changed files with 214 additions and 5 deletions

View File

@ -450,7 +450,16 @@ Symbol::final_value_is_known() const
|| parameters->options().relocatable())
&& !(this->type() == elfcpp::STT_TLS
&& parameters->options().pie()))
{
// Non-default weak undefined symbols in executable and shared
// library are always resolved to 0 at runtime.
if (this->visibility() != elfcpp::STV_DEFAULT
&& this->is_weak_undefined()
&& !parameters->options().relocatable())
return true;
return false;
}
// If the symbol is not from an object file, and is not undefined,
// then it is defined, and known.

View File

@ -709,6 +709,13 @@ class Symbol
if (this->is_absolute())
return false;
// Non-default weak undefined symbols in executable and shared
// library are always resolved to 0 at runtime.
if (this->visibility() != elfcpp::STV_DEFAULT
&& this->is_weak_undefined()
&& !parameters->options().relocatable())
return false;
// An absolute reference within a position-independent output file
// will need a dynamic relocation.
if ((flags & ABSOLUTE_REF)

View File

@ -865,6 +865,23 @@ weak_undef_file3.o: weak_undef_file3.cc
weak_undef_file4.o: weak_undef_file4.cc
$(CXXCOMPILE) -c -o $@ $<
check_PROGRAMS += weak_undef_test_3
weak_undef_test_3_SOURCES = weak_undef_test_3.c
weak_undef_test_3_DEPENDENCIES = gcctestdir/ld
weak_undef_test_3_CFLAGS = -fPIE
weak_undef_test_3_LDFLAGS = -pie
check_PROGRAMS += weak_undef_test_4
weak_undef_test_4_SOURCES = weak_undef_test_4.c
weak_undef_test_4_DEPENDENCIES = gcctestdir/ld weak_undef_lib_4.so
weak_undef_test_4_LDADD = weak_undef_lib_4.so
weak_undef_test_4_LDFLAGS = -Wl,-R,.
MOSTLYCLEANFILES += weak_undef_lib_4.o weak_undef_lib_4.so
weak_undef_lib_4.o: weak_undef_lib_4.c
$(COMPILE) -fPIC -c -o $@ $<
weak_undef_lib_4.so: gcctestdir/ld weak_undef_lib_4.o
$(LINK) -shared -o $@ weak_undef_lib_4.o
if FN_PTRS_IN_SO_WITHOUT_PIC
check_PROGRAMS += weak_undef_nonpic_test
MOSTLYCLEANFILES += alt/weak_undef_lib_nonpic.so

View File

@ -211,7 +211,9 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ eh_test_2.sects \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared.dbg \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ alt/weak_undef_lib.so \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ libweak_undef_2.a
@GCC_TRUE@@NATIVE_LINKER_TRUE@ libweak_undef_2.a \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_undef_lib_4.o \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_undef_lib_4.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_5 = icf_virtual_function_folding_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ large_symbol_alignment \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ basic_test basic_pic_test \
@ -269,7 +271,9 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@GCC_TRUE@@HAVE_STATIC_TRUE@@NATIVE_LINKER_TRUE@am__append_16 = exception_static_test
@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_17 = weak_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_undef_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_undef_test_2
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_undef_test_2 \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_undef_test_3 \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_undef_test_4
@GCC_FALSE@weak_test_DEPENDENCIES =
@NATIVE_LINKER_FALSE@weak_test_DEPENDENCIES =
@FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_18 = weak_undef_nonpic_test
@ -1237,7 +1241,9 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS)
@GCC_TRUE@@HAVE_STATIC_TRUE@@NATIVE_LINKER_TRUE@am__EXEEXT_13 = exception_static_test$(EXEEXT)
@GCC_TRUE@@NATIVE_LINKER_TRUE@am__EXEEXT_14 = weak_test$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_undef_test$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_undef_test_2$(EXEEXT)
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_undef_test_2$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_undef_test_3$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_undef_test_4$(EXEEXT)
@FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__EXEEXT_15 = weak_undef_nonpic_test$(EXEEXT)
@GCC_TRUE@@NATIVE_LINKER_TRUE@am__EXEEXT_16 = \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_alias_test$(EXEEXT) \
@ -2247,6 +2253,16 @@ weak_undef_test_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
weak_undef_test_2_OBJECTS = $(am_weak_undef_test_2_OBJECTS)
weak_undef_test_2_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
$(weak_undef_test_2_LDFLAGS) $(LDFLAGS) -o $@
@GCC_TRUE@@NATIVE_LINKER_TRUE@am_weak_undef_test_3_OBJECTS = weak_undef_test_3-weak_undef_test_3.$(OBJEXT)
weak_undef_test_3_OBJECTS = $(am_weak_undef_test_3_OBJECTS)
weak_undef_test_3_LDADD = $(LDADD)
weak_undef_test_3_LINK = $(CCLD) $(weak_undef_test_3_CFLAGS) $(CFLAGS) \
$(weak_undef_test_3_LDFLAGS) $(LDFLAGS) -o $@
@GCC_TRUE@@NATIVE_LINKER_TRUE@am_weak_undef_test_4_OBJECTS = \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_undef_test_4.$(OBJEXT)
weak_undef_test_4_OBJECTS = $(am_weak_undef_test_4_OBJECTS)
weak_undef_test_4_LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(weak_undef_test_4_LDFLAGS) $(LDFLAGS) -o $@
@GCC_TRUE@@NATIVE_LINKER_TRUE@am_weak_unresolved_symbols_test_OBJECTS = weak_unresolved_symbols_test-weak_unresolved_symbols_test.$(OBJEXT)
weak_unresolved_symbols_test_OBJECTS = \
$(am_weak_unresolved_symbols_test_OBJECTS)
@ -2391,7 +2407,8 @@ SOURCES = $(libgoldtest_a_SOURCES) $(aarch64_pr23870_SOURCES) \
$(ver_test_8_SOURCES) $(ver_test_9_SOURCES) \
$(weak_alias_test_SOURCES) weak_plt.c $(weak_test_SOURCES) \
$(weak_undef_nonpic_test_SOURCES) $(weak_undef_test_SOURCES) \
$(weak_undef_test_2_SOURCES) \
$(weak_undef_test_2_SOURCES) $(weak_undef_test_3_SOURCES) \
$(weak_undef_test_4_SOURCES) \
$(weak_unresolved_symbols_test_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
@ -3118,6 +3135,14 @@ DEPENDENCIES = \
@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_test_2_DEPENDENCIES = gcctestdir/ld libweak_undef_2.a
@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_test_2_LDFLAGS = -u weak_undef_2
@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_test_2_LDADD = -L . -lweak_undef_2
@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_test_3_SOURCES = weak_undef_test_3.c
@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_test_3_DEPENDENCIES = gcctestdir/ld
@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_test_3_CFLAGS = -fPIE
@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_test_3_LDFLAGS = -pie
@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_test_4_SOURCES = weak_undef_test_4.c
@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_test_4_DEPENDENCIES = gcctestdir/ld weak_undef_lib_4.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_test_4_LDADD = weak_undef_lib_4.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_test_4_LDFLAGS = -Wl,-R,.
@FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_nonpic_test_SOURCES = weak_undef_test.cc
@FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_nonpic_test_DEPENDENCIES = gcctestdir/ld weak_undef_lib_nonpic.so alt/weak_undef_lib_nonpic.so
@FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_nonpic_test_LDFLAGS = -Wl,-R,alt
@ -4743,6 +4768,14 @@ weak_undef_test_2$(EXEEXT): $(weak_undef_test_2_OBJECTS) $(weak_undef_test_2_DEP
@rm -f weak_undef_test_2$(EXEEXT)
$(AM_V_CXXLD)$(weak_undef_test_2_LINK) $(weak_undef_test_2_OBJECTS) $(weak_undef_test_2_LDADD) $(LIBS)
weak_undef_test_3$(EXEEXT): $(weak_undef_test_3_OBJECTS) $(weak_undef_test_3_DEPENDENCIES) $(EXTRA_weak_undef_test_3_DEPENDENCIES)
@rm -f weak_undef_test_3$(EXEEXT)
$(AM_V_CCLD)$(weak_undef_test_3_LINK) $(weak_undef_test_3_OBJECTS) $(weak_undef_test_3_LDADD) $(LIBS)
weak_undef_test_4$(EXEEXT): $(weak_undef_test_4_OBJECTS) $(weak_undef_test_4_DEPENDENCIES) $(EXTRA_weak_undef_test_4_DEPENDENCIES)
@rm -f weak_undef_test_4$(EXEEXT)
$(AM_V_CCLD)$(weak_undef_test_4_LINK) $(weak_undef_test_4_OBJECTS) $(weak_undef_test_4_LDADD) $(LIBS)
weak_unresolved_symbols_test$(EXEEXT): $(weak_unresolved_symbols_test_OBJECTS) $(weak_unresolved_symbols_test_DEPENDENCIES) $(EXTRA_weak_unresolved_symbols_test_DEPENDENCIES)
@rm -f weak_unresolved_symbols_test$(EXEEXT)
$(AM_V_CXXLD)$(weak_unresolved_symbols_test_LINK) $(weak_unresolved_symbols_test_OBJECTS) $(weak_unresolved_symbols_test_LDADD) $(LIBS)
@ -4915,6 +4948,8 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/weak_test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/weak_undef_test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/weak_undef_test_2.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/weak_undef_test_3-weak_undef_test_3.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/weak_undef_test_4.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/weak_unresolved_symbols_test-weak_unresolved_symbols_test.Po@am__quote@
.c.o:
@ -5197,6 +5232,20 @@ pr20308e_test-pr20308_main.obj: pr20308_main.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pr20308e_test_CFLAGS) $(CFLAGS) -c -o pr20308e_test-pr20308_main.obj `if test -f 'pr20308_main.c'; then $(CYGPATH_W) 'pr20308_main.c'; else $(CYGPATH_W) '$(srcdir)/pr20308_main.c'; fi`
weak_undef_test_3-weak_undef_test_3.o: weak_undef_test_3.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(weak_undef_test_3_CFLAGS) $(CFLAGS) -MT weak_undef_test_3-weak_undef_test_3.o -MD -MP -MF $(DEPDIR)/weak_undef_test_3-weak_undef_test_3.Tpo -c -o weak_undef_test_3-weak_undef_test_3.o `test -f 'weak_undef_test_3.c' || echo '$(srcdir)/'`weak_undef_test_3.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/weak_undef_test_3-weak_undef_test_3.Tpo $(DEPDIR)/weak_undef_test_3-weak_undef_test_3.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='weak_undef_test_3.c' object='weak_undef_test_3-weak_undef_test_3.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(weak_undef_test_3_CFLAGS) $(CFLAGS) -c -o weak_undef_test_3-weak_undef_test_3.o `test -f 'weak_undef_test_3.c' || echo '$(srcdir)/'`weak_undef_test_3.c
weak_undef_test_3-weak_undef_test_3.obj: weak_undef_test_3.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(weak_undef_test_3_CFLAGS) $(CFLAGS) -MT weak_undef_test_3-weak_undef_test_3.obj -MD -MP -MF $(DEPDIR)/weak_undef_test_3-weak_undef_test_3.Tpo -c -o weak_undef_test_3-weak_undef_test_3.obj `if test -f 'weak_undef_test_3.c'; then $(CYGPATH_W) 'weak_undef_test_3.c'; else $(CYGPATH_W) '$(srcdir)/weak_undef_test_3.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/weak_undef_test_3-weak_undef_test_3.Tpo $(DEPDIR)/weak_undef_test_3-weak_undef_test_3.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='weak_undef_test_3.c' object='weak_undef_test_3-weak_undef_test_3.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(weak_undef_test_3_CFLAGS) $(CFLAGS) -c -o weak_undef_test_3-weak_undef_test_3.obj `if test -f 'weak_undef_test_3.c'; then $(CYGPATH_W) 'weak_undef_test_3.c'; else $(CYGPATH_W) '$(srcdir)/weak_undef_test_3.c'; fi`
.cc.o:
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@ -6832,6 +6881,20 @@ weak_undef_test_2.log: weak_undef_test_2$(EXEEXT)
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
weak_undef_test_3.log: weak_undef_test_3$(EXEEXT)
@p='weak_undef_test_3$(EXEEXT)'; \
b='weak_undef_test_3'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
weak_undef_test_4.log: weak_undef_test_4$(EXEEXT)
@p='weak_undef_test_4$(EXEEXT)'; \
b='weak_undef_test_4'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
weak_undef_nonpic_test.log: weak_undef_nonpic_test$(EXEEXT)
@p='weak_undef_nonpic_test$(EXEEXT)'; \
b='weak_undef_nonpic_test'; \
@ -8264,6 +8327,10 @@ uninstall-am:
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -o $@ $<
@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_file4.o: weak_undef_file4.cc
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -o $@ $<
@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_lib_4.o: weak_undef_lib_4.c
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -fPIC -c -o $@ $<
@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_lib_4.so: gcctestdir/ld weak_undef_lib_4.o
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -shared -o $@ weak_undef_lib_4.o
@FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_file1_nonpic.o: weak_undef_file1.cc
@FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -o $@ $<
@FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_file2_nonpic.o: weak_undef_file2.cc

View File

@ -0,0 +1,40 @@
/* weak_undef_lib_4.c -- test non-default weak undefined symbol in DSO.
Copyright (C) 2024 Free Software Foundation, Inc.
This file is part of gold.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
/* Non-default weak undefined symbol in DSO should be resolved to 0 at
runtime. */
#include <stdlib.h>
extern void undefined (void) __attribute__((visibility("hidden"))) __attribute__((weak));
extern void protected (void) __attribute__((visibility("protected"))) __attribute__((weak));
extern void foo (void);
void
foo (void)
{
if (&undefined != NULL)
abort ();
if (&protected != NULL)
abort ();
}

View File

@ -0,0 +1,40 @@
/* weak_undef_test_3.c -- test non-default weak undefined symbol in PIE.
Copyright (C) 2024 Free Software Foundation, Inc.
This file is part of gold.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
/* Non-default weak undefined symbol in PIE should be resolved to 0 at
runtime. */
#include <stdlib.h>
extern void undefined (void) __attribute__((visibility("hidden"))) __attribute__((weak));
extern void protected (void) __attribute__((visibility("protected"))) __attribute__((weak));
int
main (void)
{
if (&undefined != NULL)
abort ();
if (&protected != NULL)
abort ();
return 0;
}

View File

@ -0,0 +1,29 @@
/* weak_undef_test_4.c -- test non-default weak undefined symbol in DSO.
Copyright (C) 2024 Free Software Foundation, Inc.
This file is part of gold.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
extern void foo (void);
int
main (void)
{
foo ();
return 0;
}