llvm-mingw
llvm-mingw copied to clipboard
autoexport produced many unneeded symbols
If compile with g++ , only the functions in the code will be exported, but if use clang some symbols from the STL are exported.
If can fix this issue, may be alleviate #197 issue
The symbols from the STL may be prefix with _ZNKSt3__1 (for const export)and _ZNSt3__1 (for non const export).
class Test1 {
public:
void test();
};
#include <iostream>
#include "exp.h"
void Test1::test() {
std::cout << "cpp fun";
}
void Test(){
std::cout << "Hello World!";
}
build with g++ -O2 -shared -o test.dll -Wl,--out-implib,libtest.dll.a
File: test.dll
Format: COFF-x86-64
Arch: x86_64
AddressSize: 64bit
Export {
Ordinal: 1
Name: _Z4Testv
RVA: 0x13D0
}
Export {
Ordinal: 2
Name: _ZN5Test14testEv
RVA: 0x13B0
}
build with clang++ -O2 -shared -o test.dll -Wl,--out-implib,libtest.dll.a
File: test.dll
Format: COFF-x86-64
Arch: x86_64
AddressSize: 64bit
Export {
Ordinal: 0
Name:
RVA: 0x0
}
Export {
Ordinal: 1
Name: _Z4Testv
RVA: 0x1410
}
Export {
Ordinal: 2
Name: _ZN5Test14testEv
RVA: 0x13F0
}
Export {
Ordinal: 3
Name: _ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE6sentryD2Ev
RVA: 0x16C0
}
Export {
Ordinal: 4
Name: _ZNSt3__116__pad_and_outputIcNS_11char_traitsIcEEEENS_19ostreambuf_iteratorIT_T0_EES6_PKS4_S8_S8_RNS_8ios_baseES4_
RVA: 0x1570
}
Export {
Ordinal: 5
Name: _ZNSt3__124__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_y
RVA: 0x1430
}
Export {
Ordinal: 6
Name: __clang_call_terminate
RVA: 0x1770
}
I think the issue here is mostly about the difference between libstdc++ and libc++; when headers produce inline functions, they end up emitted in the calling object files, and it seems like libc++ uses much more such constructs. And it's not really possible to distinguish which inline functions belong to the current project vs which belong to dependencies of the current project. (Yes one could look at whether they start with something that looks like the std:: namespace - but that would break building libc++ with --export-all.)
I think you should be able to verify that by using clang+lld in a libstdc++ based environment, where I think you should get the same exported symbols (except for maybe __clang_call_terminate) as with g++.
I don't think this issue affects issue #197 much, but I'm not sure either.
With toolchain that default to GNU stuff unless specified otherwise:
g++ -O2 -shared -o test.dll -Wl,--out-implib,libtest.dll.a exp.cpp
Spoiler
$ llvm-readobj --coff-exports test.dll
File: test.dll
Format: COFF-x86-64
Arch: x86_64
AddressSize: 64bit
Export {
Ordinal: 1
Name: _Z4Testv
RVA: 0x13D0
}
Export {
Ordinal: 2
Name: _ZN5Test14testEv
RVA: 0x13B0
}
clang++ -O2 -shared -o test.dll -Wl,--out-implib,libtest.dll.a exp.cpp
Spoiler
$ llvm-readobj --coff-exports test.dll
File: test.dll
Format: COFF-x86-64
Arch: x86_64
AddressSize: 64bit
Export {
Ordinal: 1
Name: _Z4Testv
RVA: 0x13D0
}
Export {
Ordinal: 2
Name: _ZN5Test14testEv
RVA: 0x13B0
}
clang++ -O2 -shared -o test.dll -Wl,--out-implib,libtest.dll.a exp.cpp -fuse-ld=lld
Spoiler
$ llvm-readobj --coff-exports test.dll
File: test.dll
Format: COFF-x86-64
Arch: x86_64
AddressSize: 64bit
Export {
Ordinal: 0
Name:
RVA: 0x0
}
Export {
Ordinal: 1
Name: _Z4Testv
RVA: 0x13D0
}
Export {
Ordinal: 2
Name: _ZN5Test14testEv
RVA: 0x13B0
}
clang++ -O2 -shared -o test.dll -Wl,--out-implib,libtest.dll.a exp.cpp -fuse-ld=lld -stdlib=libc++
Spoiler
$ llvm-readobj --coff-exports test.dll
File: test.dll
Format: COFF-x86-64
Arch: x86_64
AddressSize: 64bit
Export {
Ordinal: 0
Name:
RVA: 0x0
}
Export {
Ordinal: 1
Name: _Z4Testv
RVA: 0x13C0
}
Export {
Ordinal: 2
Name: _ZN5Test14testEv
RVA: 0x13A0
}
Export {
Ordinal: 3
Name: _ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE6sentryD2Ev
RVA: 0x16B0
}
Export {
Ordinal: 4
Name: _ZNSt3__116__pad_and_outputIcNS_11char_traitsIcEEEENS_19ostreambuf_iteratorIT_T0_EES6_PKS4_S8_S8_RNS_8ios_baseES4_
RVA: 0x1550
}
Export {
Ordinal: 5
Name: _ZNSt3__124__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_y
RVA: 0x13E0
}
Export {
Ordinal: 6
Name: __clang_call_terminate
RVA: 0x1740
}