llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.97k stars 11.54k forks source link

std::tm type needs to be mangled as "::tm" on Solaris for g++ binary compat #33114

Open Theodor opened 7 years ago

Theodor commented 7 years ago
Bugzilla Link 33767
Version unspecified
OS Solaris

Extended Description

g++ on Solaris has special mangling twist that makes it generate non-standard mangling for std::tm, std::div_t, std::ldiv_t, std::lconv types.

W/o this twist clang fails to link with libstdc++ on testcases like this:

] cat no-tm.cc

include

struct D : std::time_get {};

int main() { D var; var.date_order(); } ] clang no-tm.cc Undefined first referenced symbol in file _ZNKSt8time_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE11do_get_timeES3_S3_RSt8ios_baseRSt12_Ios_IostatePSt2tm /var/tmp/no-tm-e5c67b.o _ZNKSt8time_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE11do_get_dateES3_S3_RSt8ios_baseRSt12_Ios_IostatePSt2tm /var/tmp/no-tm-e5c67b.o _ZNKSt8time_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE14do_get_weekdayES3_S3_RSt8ios_baseRSt12_Ios_IostatePSt2tm /var/tmp/no-tm-e5c67b.o _ZNKSt8time_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE11do_get_yearES3_S3_RSt8ios_baseRSt12_Ios_IostatePSt2tm /var/tmp/no-tm-e5c67b.o _ZNKSt8time_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE16do_get_monthnameES3_S3_RSt8ios_baseRSt12_Ios_IostatePSt2tm /var/tmp/no-tm-e5c67b.o ld: fatal: symbol referencing errors clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation) ]

Basically any signature that includes either of the aforementioned types is mangled differently than whats in libstdc++.

Namely, clang mangles std::tm as std::tm (surpise! :), while gcc does it as ::tm.

Say, first undefined symbol above:

] nm /usr/lib/libstdc++.so | grep _ZNKSt8time_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE11do_get_timeES3_S3_RSt8ios_baseRSt12_Ios_Iostate [6646] | 533632| 276|FUNC |WEAK #0 llvm/llvm-project#1182 |_ZNKSt8time_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE11do_get_timeES3_S3_RSt8ios_baseRSt12_Ios_IostateP2tm ]

Notice 2tm vs St2tm difference at the tail of the mangled name.

Theodor commented 7 years ago

See gcc mail thread that introduces this hack: https://gcc.gnu.org/ml/gcc-patches/2011-08/msg00834.html

Theodor commented 7 years ago

assigned to @Theodor

AaronBallman commented 1 month ago

This issue hit our own project in: https://github.com/llvm/llvm-project/pull/99075