binutils-gdb/gold/testsuite/weak_undef_lib_4.c
H.J. Lu 229ecf80f3 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>
2024-08-31 04:28:43 -07:00

41 lines
1.3 KiB
C

/* 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 ();
}