clang -O2 doesn't export the same symbols as gcc with virtual destructor
source link: https://bugs.llvm.org/show_bug.cgi?id=45322
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
New user self-registration is disabled due to spam. For an account please email [email protected] with your e-mail address and full name.
BugĀ 45322 - clang -O2 doesn't export the same symbols as gcc with virtual destructor
Reported: 2020-03-26 16:13 PDT by Sylvestre Ledru
Modified: 2020-03-27 13:18 PDT (History) CC List: 2 users (show)
Attachments Add an attachment (proposed patch, testcase, etc.)
Happening on a bunch of cases here: https://clang.debian.net/status.php?version=9.0.1&key=CHANGE_SYM_LIB Probably not a recent issue === a.cpp === #include <stddef.h> namespace pugi { class xml_writer { public: virtual ~xml_writer() {} }; class a : xml_writer { virtual void b(const void *, size_t); }; void a::b(const void *, size_t) {} } // namespace pugi === script ARG=" -O2 -o pugixml.cpp.o -c a.cpp" CXX=/usr/bin/clang++ $CXX $ARG mv pugixml.cpp.o clang.o CXX=/usr/bin/g++-9 $CXX $ARG mv pugixml.cpp.o gcc.o nm clang.o |grep -q N4pugi10xml_writerD2Ev nm gcc.o |grep -q N4pugi10xml_writerD2Ev === Will show: nm clang.o |grep N4pugi10xml_writerD2Ev 0000000000000000 W _ZN4pugi10xml_writerD2Ev nm gcc.o |grep N4pugi10xml_writerD2Ev === without -O2, gcc will generate the symbol too. maybe clang should remove too when -O2 is used?
The vtable for "a" needs to refer to some function to represent its virtual destructor. clang chooses xml_writer::~xml_writer. gcc chooses a::~a. I don't think the choice has any practical effect.
> I don't think the choice has any practical effect. Probably not indeed. However, some linux distros like Debian & Ubuntu are keeping track of symbols in C/C++ libraries: https://wiki.debian.org/UsingSymbolsFiles (for changes in ABI). This different behavior is causing packages to fail to build when looking for the symbol list. Maybe I could hack the tool [1] to ignore such patterns? [1] https://manpages.debian.org/testing/dpkg-dev/dpkg-gensymbols.1.en.html
If you're looking at the set of exported symbols including inline functions, that's never going to be stable for C++ projects that aren't using something like -fvisibility-inlines-hidden. The fundamental problem is that the compiler may or may not expose the symbols in question, depending on optimization heuristics. The name of the destructor here is a relatively minor aspect of that. If you want a stable result, you probably need some way to ask the compiler to dump the complete set of symbols that are odr-used in a given translation unit. Or require that all projects use -fvisibility-inlines-hidden.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK