Handle symbol visibility/locality for PIE/PICheads/hjl/pr32219/master
commitb6b0361e15cb3d43c7e1a6de5403a4fe50960815
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 5 Feb 2015 22:28:58 +0000 (5 14:28 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 12 Feb 2015 16:01:42 +0000 (12 08:01 -0800)
tree7c5e7f2d3b97d8cce8d58f49c011e6d52ba87831
parenta5a520294191da394b276e6dc3296fe90f7ec63e
Handle symbol visibility/locality for PIE/PIC

If a hidden weak symbol isn't defined in the TU, we can't assume it will
be defined in another TU at link time.  It makes a difference in code
generation when compiling for PIC. If we assume that a hidden weak
undefined symbol is local, the address checking may be optimized out and
leads to the wrong code.  This means that a symbol with user specified
visibility is local only if it is locally resolved or defined, not weak
or not compiling for PIC.  When symbol visibility is specified in the
source, we should always output symbol visibility even if symbol isn't
local to the TU.

If a global data symbol is defined in the TU, it is always local to the
executable, regardless if it is a common symbol or not.  If we aren't
compiling for shared library, locally defined global data symbol binds
locally.

Since some targets call default_binds_local_p_1 directly and depend on
the old behavior of default_binds_local_p_1.  This patch copies
default_binds_local_p_1 to default_binds_local_p_2 and changes the
behavior of default_binds_local_p by calling default_binds_local_p_2
instead of default_binds_local_p_1.

gcc/

PR rtl-optimization/32219
* cgraphunit.c (varpool_node::finalize_decl): Set definition
first before calling notice_global_symbol so that it is
available to notice_global_symbol.
* varasm.c (default_binds_local_p_2): Copied from
default_binds_local_p_1.  Resolve defined data symbol locally if
not building shared library.  Resolve symbol with user specified
visibility locally only if it is locally resolved or defined, not
weak or not compiling for PIC.
(default_binds_local_p): Replace default_binds_local_p_1 with
default_binds_local_p_2.
(default_elf_asm_output_external): Always output visibility
specified in the source.

gcc/testsuite/

PR rtl-optimization/32219
* gcc.dg/visibility-22.c: New test.
* gcc.dg/visibility-23.c: Likewise.
* gcc.target/i386/pr32219-1.c: Likewise.
* gcc.target/i386/pr32219-2.c: Likewise.
* gcc.target/i386/pr32219-3.c: Likewise.
* gcc.target/i386/pr32219-4.c: Likewise.
* gcc.target/i386/pr32219-5.c: Likewise.
* gcc.target/i386/pr32219-6.c: Likewise.
* gcc.target/i386/pr32219-7.c: Likewise.
* gcc.target/i386/pr32219-8.c: Likewise.
* gcc.target/i386/pr64317.c: Expect GOTOFF relocation instead
of GOT relocation.
13 files changed:
gcc/cgraphunit.c
gcc/testsuite/gcc.dg/visibility-22.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/visibility-23.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr32219-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr32219-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr32219-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr32219-4.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr32219-5.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr32219-6.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr32219-7.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr32219-8.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr64317.c
gcc/varasm.c