How to optimize a large project in llvm pass?

I have written MyPass.cpp and I use “EP_FullLinkTimeOptimizationLast”.
I compile it and get rely on some other code, such as,Init.c and Helper.c.
So, I use following commands to get a static library libmypass-rt.a.
$ clang -fsanitize=safe-stack -c -emit-llvm -fpic -Wall -Wextra -O2 -I …/include -o obj/helpers.o helpers.c
$ clang -fsanitize=safe-stack -c -emit-llvm -fpic -Wall -Wextra -O2 -I …/include -o obj/init.o init.c

$ ar rcs obj/libmypass-rt.a obj/helpers.o obj/init.o

When mypass optimizes the target program, it reles on libmypass-rt.a library. So I need to link libmypass-rt.a to the target program, then optimize after link.
So, I need LTO.
I use following commands:

$ export CC=clang
$ export CXX=clang++
$ export RANLIB=llvm-ranlib
$ export LIBS=“path/to/…/libmypass-rt.a”
$ export CFLAGS=" -fsanitize=safe-stack -Wall -Wextra -fpic -flto -Xclang -load -Xclang path/to/…/"
$ export LDFLAGS=" -flto -fuse-ld=gold"
$ ./configure

$ make
But, errors occurred. I check out config.log

/usr/bin/ error: path/to/…/libmemsentry-rt.a: no archive symbol table (run ranlib)
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)

What shuold I do?
If this problem is solved, please tell me whether my method can achieve my goal?



-Xclang -load -Xclang path/to/.../ is gonna load the pass inside clang, however clang will invoke the linker separately and it won’t have your pass. I don’t know if gold or lld can load dynamically passes like this?
An alternative it to link your pass statically with the gold plugin or with lld.


To me it looks like you may just want to link your output binary with libmypass-rt.a. Is that correct? For that you only need to pass libmypass-rt.a on the command line when linking (as you would any other library that you want linked in). This is really well explained in this blog by Adrian Sampson: Adrian Sampson: LLVM for Grad Students

@Mehdi Re loading plugins in LLD: ⚙ D75879 [lld]Enabling loading LLVM pass plugins