Fix #3929 - Enable LTO in sys/static.sh ##build (#17141)

* Fix #3929 - Enable LTO in sys/static.sh
* Update Ubuntu to 20.04 for static build
* Use `gcc-ar` when needed
* Do not use "c" option for ${AR}
* Use `$$AR` instead of `$AR`
* Aim to fix  `-dynamiclib` issue outside darwin
* Run tests for static LTO build

Co-authored-by: pancake <pancake@nopcode.org>
Co-authored-by: Anton Kochkov <xvilka@gmail.com>
This commit is contained in:
pancake 2020-08-13 07:55:39 +02:00 committed by GitHub
parent bb3e80c040
commit 8b33d764a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 63 additions and 45 deletions

View file

@ -11,7 +11,7 @@ on:
jobs:
build:
name: ubuntu-static-tests
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
if: github.event_name != 'pull_request' || contains(github.event.pull_request.head.ref, 'static')
@ -31,3 +31,5 @@ jobs:
run: |
r2 -v
r2r -v
cd test
make

View file

@ -91,21 +91,22 @@ ifeq ($(OSTYPE),bsd)
endif
_libr.${EXT_AR}: .libr
-${AR} crs $@ .libr/*.o
-${AR} -rs $@ .libr/*.o
# this code should be in do-ar-sh not inlined here..
.libr2: $(wildcard */libr_*.${EXT_AR}) ../shlr/libr_shlr.${EXT_AR}
rm -rf .libr2
mkdir -p .libr2
-for LIB in $^ ; do \
BN=`basename $$LIB` ; \
echo $$BN ; \
mkdir -p .libr2/$$BN ; \
echo .libr2/$$BN $$LIB; ${AR} ; \
( cd .libr2/$$BN ; pwd ; du -hs ../../$$LIB; ${AR} x ../../$$LIB ) ; \
echo "( cd .libr2/$$BN ; pwd ; du -hs ../../$$LIB; ${AR} -x ../../$$LIB )" ; \
( cd .libr2/$$BN ; pwd ; du -hs ../../$$LIB; ${AR} -x ../../$$LIB ) ; \
done
libr.${EXT_AR}: .libr2
-${AR} crs $@ .libr2/*/*.o
-${AR} -rs $@ .libr2/*/*.o
ifeq (1,$(WITH_GPL))
E+=../shlr/grub/libgrubfs.${EXT_AR}
@ -130,11 +131,17 @@ else
E+=../shlr/capstone/libcapstone.${EXT_AR}
endif
ifeq ($(OSTYPE),darwin)
libr_LDFLAGS=-dynamiclib -shared
else
libr_LDFLAGS=-shared
endif
libr.${EXT_SO}: .libr2
ifeq (${COMPILER},emscripten)
echo nothing to do here
else
$(CC) -fvisibility=hidden $(MLFLAGS) ${LINK} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -shared -dynamiclib -o libr.${EXT_SO} \
$(CC) -fvisibility=hidden $(MLFLAGS) ${LINK} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} $(libr_LDFLAGS) -o libr.${EXT_SO} \
.libr2/*/*.o \
../shlr/gdb/lib/libgdbr.${EXT_AR} ../shlr/java/libr_java.${EXT_AR} \
../shlr/libr_shlr.${EXT_AR} ../shlr/mpc/libmpc.${EXT_AR} $(E) \

View file

@ -30,14 +30,14 @@ for a in ${LIBS} ; do
mkdir -p "$TMP/$a/$b"
ORIG="$PWD/$a.$b"
lipo -thin $b -output $a.$b $a
echo "cd $TMP/$a/$b : ar x $ORIG"
( cd $TMP/$a/$b ; ar x $ORIG )
echo "cd $TMP/$a/$b : ${AR} -x $ORIG"
( cd $TMP/$a/$b ; ${AR} -x $ORIG )
rm -f $a.$b
done
else
mkdir -p "${TMP}/${a}"
ORIG="$PWD/$a"
( cd $TMP/$a ; ar x $ORIG )
( cd $TMP/$a ; ${AR} -x $ORIG )
echo $a
fi
done
@ -51,6 +51,6 @@ if [ -z "${OBJS}" ]; then
exit 1
else
rm -f "${LIB}"
${AR} qv "${LIB}" ${OBJS}
${AR} -qv "${LIB}" ${OBJS}
${RANLIB} "${LIB}"
fi

View file

@ -13,8 +13,8 @@ include $(LTOP)/rules.mk
libfile.a:
${CC} -c ${CFLAGS} ${SRC}
ar q libfile.a *.o
ranlib libfile.a
${AR} q libfile.a *.o
${RANLIB} libfile.a
BIN=file${EXT_EXE}
${BIN}:

View file

@ -407,13 +407,13 @@ ifeq ($(CC),emcc)
for LIB in ${SHLRS} ; do \
if [ -f "$${LIB}" ]; then emcc -emit-llvm -nostdlib -Wl,--whole-archive -o .libr/$$(basename $${LIB}.a).o $${LIB} ; fi ; \
done
${AR} crs $@ .libr/*.o
${AR} rs $@ .libr/*.o
$(RANLIB) $@
else
for LIB in ${SHLRS} ; do \
if [ -f "$${LIB}" ]; then ${PARTIALLD} -o .libr/$$(basename $${LIB}.a).o $${LIB} ; fi ; \
done
${AR} crs $@ .libr/*.o
${AR} rs $@ .libr/*.o
$(RANLIB) $@
endif

View file

@ -24,16 +24,16 @@
# preinst, postinst, prerm, postrm - optional control shell scripts
# These fields are used to build the control file:
# PACKAGE =
# VERSION =
# ARCH =
# SECTION =
# PRIORITY =
# MAINTAINER =
# DEPENDS =
# PACKAGE =
# VERSION =
# ARCH =
# SECTION =
# PRIORITY =
# MAINTAINER =
# DEPENDS =
#
# SOURCE_DIR =
# ICON_SOURCE =
# ICON_SOURCE =
# (ICON_SOURCE is optional)
# *** NO USER CHANGES REQUIRED BEYOND THIS POINT ***
@ -97,7 +97,7 @@ ${PACKAGE_DIR}/build: ${PACKAGE_DIR}/debian-binary ${PACKAGE_DIR}/control \
# Convert GNU ar to BSD ar that debian requires.
# Note: Order of files within ar archive is important!
${PACKAGE_DIR}/${PACKAGE}_${VERSION}_${ARCH}.deb: ${PACKAGE_DIR}/build
ar -rc $@ $</debian-binary $</control.tar.gz $</data.tar.gz
${AR} -rc $@ $</debian-binary $</control.tar.gz $</data.tar.gz
#sed -e 's|^\([^/]\+\)/ \(.*\)|\1 \2|g' $@tmp > $@fail
#rm -f $@tmp
#mv $@fail $@

View file

@ -24,16 +24,16 @@
# preinst, postinst, prerm, postrm - optional control shell scripts
# These fields are used to build the control file:
# PACKAGE =
# VERSION =
# ARCH =
# SECTION =
# PRIORITY =
# MAINTAINER =
# DEPENDS =
# PACKAGE =
# VERSION =
# ARCH =
# SECTION =
# PRIORITY =
# MAINTAINER =
# DEPENDS =
#
# SOURCE_DIR =
# ICON_SOURCE =
# ICON_SOURCE =
# (ICON_SOURCE is optional)
# *** NO USER CHANGES REQUIRED BEYOND THIS POINT ***
@ -102,7 +102,7 @@ ${PACKAGE_DIR}/build: ${PACKAGE_DIR}/debian-binary ${PACKAGE_DIR}/control \
# Convert GNU ar to BSD ar that debian requires.
# Note: Order of files within ar archive is important!
${PACKAGE_DIR}/${PACKAGE}_${VERSION}_${ARCH}.deb: ${PACKAGE_DIR}/build
ar -rc $@ $</debian-binary $</control.tar.xz $</data.tar.xz
${AR} -rc $@ $</debian-binary $</control.tar.xz $</data.tar.xz
#sed -e 's|^\([^/]\+\)/ \(.*\)|\1 \2|g' $@tmp > $@fail
#rm -f $@tmp
#mv $@fail $@

View file

@ -24,16 +24,16 @@
# preinst, postinst, prerm, postrm - optional control shell scripts
# These fields are used to build the control file:
# PACKAGE =
# VERSION =
# ARCH =
# SECTION =
# PRIORITY =
# MAINTAINER =
# DEPENDS =
# PACKAGE =
# VERSION =
# ARCH =
# SECTION =
# PRIORITY =
# MAINTAINER =
# DEPENDS =
#
# SOURCE_DIR =
# ICON_SOURCE =
# ICON_SOURCE =
# (ICON_SOURCE is optional)
# *** NO USER CHANGES REQUIRED BEYOND THIS POINT ***
@ -87,7 +87,7 @@ ${PACKAGE_DIR}/build: ${PACKAGE_DIR}/debian-binary ${PACKAGE_DIR}/control \
# Convert GNU ar to BSD ar that debian requires.
# Note: Order of files within ar archive is important!
${PACKAGE_DIR}/${PACKAGE}_${VERSION}_${ARCH}.deb: ${PACKAGE_DIR}/build
ar -rc $@ $</debian-binary $</control.tar.gz $</data.tar.gz
${AR} -rc $@ $</debian-binary $</control.tar.gz $</data.tar.gz
#sed -e 's|^\([^/]\+\)/ \(.*\)|\1 \2|g' $@tmp > $@fail
#rm -f $@tmp
#mv $@fail $@

View file

@ -9,12 +9,12 @@ sys/meson.py --options use_libuv=false use_sys_magic=false || exit 1
echo $a
b=`basename $a`
mkdir a/$b
(cd a/$b ; ar xv ../../$a) > /dev/null
(cd a/$b ; ${AR} xv ../../$a) > /dev/null
done
(
rm -f libr.a
cd a
ar crs ../libr.a */*.o
${AR} rs ../libr.a */*.o
)
)
D=r2sdk

View file

@ -5,6 +5,15 @@
case "$(uname)" in
Linux)
LDFLAGS="${LDFLAGS} -lpthread -ldl -lutil -lm"
CFLAGS="${CFLAGS} -flto"
LDFLAGS="${LDFLAGS} -flto"
if [ -n "`gcc -v 2>&1 | grep gcc`" ]; then
export AR=gcc-ar
fi
;;
Darwin)
CFLAGS="${CFLAGS} -flto"
LDFLAGS="${LDFLAGS} -flto"
;;
OpenBSD)
LDFLAGS="${LDFLAGS} -lpthread -lkvm -lutil -lm"
@ -76,7 +85,7 @@ int main() {
EOF
cat .test.c
if [ -z "${CC}" ]; then
CC=gcc
gcc -v > /dev/null 2>&1 && CC=gcc
fi
# static pkg-config linking test