Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2021-03-02 10:53:06 +1000
committerAllan McRae <allan@archlinux.org>2021-03-03 14:35:52 +1000
commitc118a61f62a4b100b01504dfc5611cd08fb9e537 (patch)
treed1592fa23f633e0d9f077460d8a9204ca1548d67 /scripts
parent4a0891f49d29458e1b93d95f8121f8096bb02727 (diff)
Strip LTO symbols from distributed .a/.o files
GCC's LTO implementation emits bytecodes into .o files it generates. These bytecodes are _not_ considered stable from one release of GCC to the next. There we need to strip the LTO bytecode out of any .o (and .a) file that gets installed into the package. Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/libmakepkg/tidy/strip.sh.in13
1 files changed, 13 insertions, 0 deletions
diff --git a/scripts/libmakepkg/tidy/strip.sh.in b/scripts/libmakepkg/tidy/strip.sh.in
index 720b8eb3..ceb2a108 100644
--- a/scripts/libmakepkg/tidy/strip.sh.in
+++ b/scripts/libmakepkg/tidy/strip.sh.in
@@ -103,6 +103,16 @@ strip_file() {
rm -f "$tempfile"
}
+strip_lto() {
+ local binary=$1;
+
+ local tempfile=$(mktemp "$binary.XXXXXX")
+ if strip -R .gnu.lto_* -R .gnu.debuglto_* -N __gnu_lto_v1 "$binary" -o "$tempfile"; then
+ cat "$tempfile" > "$binary"
+ fi
+ rm -f "$tempfile"
+}
+
tidy_strip() {
if check_option "strip" "y"; then
@@ -121,6 +131,7 @@ tidy_strip() {
local binary strip_flags
find . -type f -perm -u+w -print0 2>/dev/null | while IFS= read -rd '' binary ; do
+ local STRIPLTO=0
case "$(LC_ALL=C readelf -h "$binary" 2>/dev/null)" in
*Type:*'DYN (Shared object file)'*) # Libraries (.so) or Relocatable binaries
strip_flags="$STRIP_SHARED";;
@@ -129,6 +140,7 @@ tidy_strip() {
*Type:*'REL (Relocatable file)'*) # Libraries (.a) or objects
if ar t "$binary" &>/dev/null; then # Libraries (.a)
strip_flags="$STRIP_STATIC"
+ STRIPLTO=1
elif [[ $binary = *'.ko' ]]; then # Kernel module
strip_flags="$STRIP_SHARED"
else
@@ -139,6 +151,7 @@ tidy_strip() {
continue ;;
esac
strip_file "$binary" ${strip_flags}
+ (( STRIPLTO )) && strip_lto "$binary"
done
fi
}