llvm.org GIT mirror llvm / f3d0806
[libcxx] Don't use -fvisibility-global-new-delete-hidden when not defining them When builing the hermetic static library, the compiler switch -fvisibility-global-new-delete-hidden is necessary to get the new and delete operator definitions made correctly. However, when those definitions are not included in the library, then this switch does harm. With lld (though not all linkers) setting STV_HIDDEN on SHN_UNDEF symbols makes it an error to leave them undefined or defined via dynamic linking that should generate PLTs for -shared linking (lld makes this a hard error even without -z defs). Though leaving the symbols undefined would usually work in practice if the linker were to allow it (and the user didn't pass -z defs), this actually indicates a real problem that could bite some target configurations more subtly at runtime. For example, x86-32 ELF -fpic code generation uses hidden visibility on declarations in the caller's scope as a signal that the call will never be resolved to a PLT entry and so doesn't have to meet the special ABI requirements for PLT calls (setting %ebx). Since these functions might actually be resolved to PLT entries at link time (we don't know what the user is linking in when the hermetic library doesn't provide all the symbols itself), it's not safe for the compiler to treat their declarations at call sites as having hidden visibility. Differential Revision: https://reviews.llvm.org/D61571 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360003 91177308-0d34-0410-b5e6-96231b3b80d8 Petr Hosek 5 months ago
1 changed file(s) with 8 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
8383 "_CRT_STDIO_ISO_WIDE_SPECIFIERS",
8484 ]
8585 }
86 if (!libcxx_enable_new_delete_definitions) {
87 defines += [ "_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS" ]
88 }
8689 if (libcxx_enable_exceptions) {
8790 if (current_os == "win") {
8891 cflags_cc += [ "/EHsc" ]
9699 } else {
97100 cflags_cc += [ "-fno-exceptions" ]
98101 }
99 defines += [ "-D_LIBCPP_NO_EXCEPTIONS" ]
102 defines += [ "_LIBCPP_NO_EXCEPTIONS" ]
100103 }
101104 if (!libcxx_enable_rtti) {
102105 if (current_os == "win") {
104107 } else {
105108 cflags_cc += [ "-fno-rtti" ]
106109 }
107 defines += [ "-D_LIBCPP_NO_RTTI" ]
110 defines += [ "_LIBCPP_NO_RTTI" ]
108111 }
109112 }
110113
250253 sources = cxx_sources
251254 if (libcxx_hermetic_static_library) {
252255 cflags = [ "-fvisibility=hidden" ]
253 cflags_cc = [ "-fvisibility-global-new-delete-hidden" ]
256 if (libcxx_enable_new_delete_definitions) {
257 cflags_cc = [ "-fvisibility-global-new-delete-hidden" ]
258 }
254259 defines = [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ]
255260 }
256261 deps = [