diff mbox series

scripts: bundle-libraries.sh: fix broken SDK compiler

Message ID 20201101141602.32650-1-ynezz@true.cz
State Superseded
Delegated to: Petr Štetiar
Headers show
Series scripts: bundle-libraries.sh: fix broken SDK compiler | expand

Commit Message

Petr Štetiar Nov. 1, 2020, 2:16 p.m. UTC
Recent versions (> 5.33) of `file` report liblto_plugin.so as
executable:

 $ file liblto_plugin.so
 liblto_plugin.so.0.0.0: ELF 64-bit LSB pie executable ...

Which then leads to improper packaging of the plugin, resulting in the
broken compiler:

 configure: checking whether the C compiler works
 mips-openwrt-linux-musl/bin/ld: liblto_plugin.so: error loading plugin: liblto_plugin.so: invalid ELF header

As the LTO compiler plugin library is incorrectly packaged as SDK
executable:

 ...
 Bundling liblto_plugin.so.0.0.0
 ...

 $ head -1 ~/staging_dir/toolchain...libexec/gcc/.../liblto_plugin.so
 #!/usr/bin/env bash

Fix this by removing executable bit from shared libraries before the
bundling as it seems, that this is enough for `file` to detect it
properly again as shared library:

 $ chmod -x liblto_plugin.so

 $ file liblto_plugin.so
 liblto_plugin.so: ELF 64-bit LSB shared object ...

Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1296868
Signed-off-by: Petr Štetiar <ynezz@true.cz>
---
 scripts/bundle-libraries.sh | 1 +
 1 file changed, 1 insertion(+)

Comments

Jo-Philipp Wich Nov. 1, 2020, 4:51 p.m. UTC | #1
Hi Petr,

instead of meddling with the file permissions (which might cause
unwanted side effects for .so's that *are* supposed to be executable)
I'd suggest to simply skip *.so files by name.

Something along the lines of:

case "$BIN" in
  *.so|*.so.[0-9]*) : ;;
  *)
    [ -n "$LDD" ] && [ -x "$BIN" ] && file "$BIN" | grep -sqE
"ELF.*(executable|interpreter)" && {
      ...
    }
  ;;
esac

~ Jo
diff mbox series

Patch

diff --git a/scripts/bundle-libraries.sh b/scripts/bundle-libraries.sh
index 9efcbbd0b20e..70a88e685ac7 100755
--- a/scripts/bundle-libraries.sh
+++ b/scripts/bundle-libraries.sh
@@ -150,6 +150,7 @@  for BIN in "$@"; do
 
 	LDSO=""
 
+	[[ "$BIN" =~ \.so[\.0-9]*$ ]] && chmod -x "$BIN"
 	[ -n "$LDD" ] && [ -x "$BIN" ] && file "$BIN" | grep -sqE "ELF.*(executable|interpreter)" && {
 		for token in $("$LDD" "$BIN" 2>/dev/null); do
 			case "$token" in */*.so*)