mirror of https://github.com/google/oss-fuzz.git
bitcoin-core: enable LTO (take 3) (#10363)
take 3, along with a revival of a previous hack to run LTO only once
This commit is contained in:
parent
fc4525cc9d
commit
4c63074ffc
|
@ -26,10 +26,16 @@ if [ "$ARCHITECTURE" = "i386" ]; then
|
|||
else
|
||||
export BUILD_TRIPLET="x86_64-pc-linux-gnu"
|
||||
fi
|
||||
|
||||
# Build using ThinLTO, to avoid OOM, and other LLVM issues.
|
||||
# See https://github.com/google/oss-fuzz/pull/10123.
|
||||
sed -i 's/flto/flto=thin/g' ./depends/hosts/linux.mk
|
||||
sed -i 's/flto/flto=thin/g' ./configure.ac
|
||||
|
||||
(
|
||||
cd depends
|
||||
sed -i --regexp-extended '/.*rm -rf .*extract_dir.*/d' ./funcs.mk # Keep extracted source
|
||||
make HOST=$BUILD_TRIPLET NO_QT=1 NO_BDB=1 NO_ZMQ=1 NO_UPNP=1 NO_NATPMP=1 NO_USDT=1 -j$(nproc)
|
||||
make HOST=$BUILD_TRIPLET LTO=1 NO_QT=1 NO_BDB=1 NO_ZMQ=1 NO_UPNP=1 NO_NATPMP=1 NO_USDT=1 AR=llvm-ar RANLIB=llvm-ranlib -j$(nproc)
|
||||
)
|
||||
|
||||
# Build the fuzz targets
|
||||
|
@ -57,14 +63,18 @@ fi
|
|||
|
||||
# OSS-Fuzz requires a separate and self-contained binary for each fuzz target.
|
||||
# To inject the fuzz target name in the finished binary, compile the fuzz
|
||||
# executable with the name of the fuzz target injected into the source code.
|
||||
# executable with a "magic string" as the name of the fuzz target.
|
||||
#
|
||||
# An alternative to mocking the string in the finished binary would be to
|
||||
# replace the string in the source code and re-invoke 'make'. This is slower,
|
||||
# so use the hack.
|
||||
export MAGIC_STR="b5813eee2abc9d3358151f298b75a72264ffa119d2f71ae7fefa15c4b70b4bc5b38e87e3107a730f25891ea428b2b4fabe7a84f5bfa73c79e0479e085e4ff157"
|
||||
sed -i "s|std::getenv(\"FUZZ\")|\"$MAGIC_STR\"|g" "./src/test/fuzz/fuzz.cpp"
|
||||
make -j$(nproc)
|
||||
|
||||
# Replace the magic string with the actual name of each fuzz target
|
||||
for fuzz_target in ${FUZZ_TARGETS[@]}; do
|
||||
git checkout -- "./src/test/fuzz/fuzz.cpp"
|
||||
sed -i "s|static std::string_view g_fuzz_target;|static std::string g_fuzz_target;|g" "./src/test/fuzz/fuzz.cpp"
|
||||
sed -i "s|std::getenv(\"FUZZ\")|\"$fuzz_target\"|g" "./src/test/fuzz/fuzz.cpp"
|
||||
sed -i "s|.find(g_fuzz_target)|.find(g_fuzz_target.c_str())|g" "./src/test/fuzz/fuzz.cpp"
|
||||
make -j$(nproc)
|
||||
mv './src/test/fuzz/fuzz' "$OUT/$fuzz_target"
|
||||
python3 -c "c_str_target=b\"${fuzz_target}\x00\";c_str_magic=b\"$MAGIC_STR\";dat=open('./src/test/fuzz/fuzz','rb').read();dat=dat.replace(c_str_magic, c_str_target+c_str_magic[len(c_str_target):]);open(\"$OUT/$fuzz_target\",'wb').write(dat)"
|
||||
|
||||
chmod +x "$OUT/$fuzz_target"
|
||||
(
|
||||
|
|
Loading…
Reference in New Issue