[PATCH] D61909: Add Clang shared library with C++ exports
Wink Saville via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 14 22:39:27 PDT 2019
winksaville added a comment.
I did some quick testing.
I used cmake and ninja to build `llvm` and enabled `clang;lld;compiler-rt` subprojects:
$ cd build-beanz-clang-shlib-2-add-debug-BUILD-LINK_DYNLIB-ON
$ cmake ../llvm -G Ninja '-DLLVM_ENABLE_PROJECTS=clang;lld;compiler-rt' -DCMAKE_INSTALL_PREFIX=/home/wink/local-beanz-clang-shlib-2-add-debug-BUILD-LINK_DYNLIB-ON -DCMAKE_BUILD_TYPE=Release -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON
$ ninja
I then used `bin/clang++` to create `bin/clang-shared` and verified it ran and looked at the sizes; `bin/clang-shared` is 187K while `bin/clang-9` is 45M
$ bin/clang++ -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG -Wl,-allow-shlib-undefined -Wl,--export-dynamic -Wl,-rpath-link,/home/wink/prgs/llvm/llvm-project/build-beanz-clang-shlib-2-add-debug-BUILD-LINK_DYNLIB-ON/./lib -Wl,-O3 tools/clang/tools/driver/CMakeFiles/clang.dir/driver.cpp.o tools/clang/tools/driver/CMakeFiles/clang.dir/cc1_main.cpp.o tools/clang/tools/driver/CMakeFiles/clang.dir/cc1as_main.cpp.o tools/clang/tools/driver/CMakeFiles/clang.dir/cc1gen_reproducer_main.cpp.o -o bin/clang-shared -Wl,-rpath,"\$ORIGIN/../lib" -lpthread lib/libclang_shared.so lib/libLLVM-9svn.so
$ ./bin/clang-shared --version
clang version 9.0.0 (git at github.com:winksaville/llvm-project 2e41f82e327c9aace5b1367995357a787be77105)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/wink/prgs/llvm/llvm-project/build-beanz-clang-shlib-2-add-debug-BUILD-LINK_DYNLIB-ON/./bin
$ ls -hal bin/clang-9 bin/clang-shared
-rwxr-xr-x 1 wink users 45M May 14 17:57 bin/clang-9
-rwxr-xr-x 1 wink users 187K May 14 22:15 bin/clang-shared
And I'd previously built `clang-9` with LLVM_BUILD_LLVM_DYLIB=OFF and it is 114M:
$ ls -hal ../build-beanz-clang-shlib-2-add-debug-DYNLIB-OFF/bin/clang-9
-rwxr-xr-x 1 wink users 114M May 14 11:31 ../build-beanz-clang-shlib-2-add-debug-DYNLIB-OFF/bin/clang-9
I then compilef hi.c with `clang-shared` and ran the result:
$ cat ../hi.c
#include <stdio.h>
int main(void) {
printf("hi\n");
return 0;
}
$ ./bin/clang-shared ../hi.c -o hi
$ ./hi
hi
LGTM
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61909/new/
https://reviews.llvm.org/D61909
More information about the cfe-commits
mailing list