[pacman-dev] [PATCH 2/3] libmakepkg: use readelf instead of file for finding ELF file types
Allan McRae
allan at archlinux.org
Wed Dec 11 01:02:02 UTC 2019
On 27/11/19 7:29 am, Ethan Sommer wrote:
> Signed-off-by: Ethan Sommer <e5ten.arch at gmail.com>
> ---
> scripts/libmakepkg/tidy/strip.sh.in | 26 ++++++++++++--------------
> 1 file changed, 12 insertions(+), 14 deletions(-)
>
This diff is an absolute pain to read!
I went through all files on my system, and confirmed this change does
what it is supposed to. Files are all stripped the same way.
Onto the issues Eli brought up:
1) Hiding errors from readelf. If readelf errors in any way, we are
not going to be stripping the file anyway. So I am fine with that.
2) Format of output. I am OK with this given multiple implementations
use the same format, and we already rely on parsing the readelf output
when making debug packages.
In summmary. Ack.
A
> diff --git a/scripts/libmakepkg/tidy/strip.sh.in b/scripts/libmakepkg/tidy/strip.sh.in
> index 1bd810f0..301d1989 100644
> --- a/scripts/libmakepkg/tidy/strip.sh.in
> +++ b/scripts/libmakepkg/tidy/strip.sh.in
> @@ -111,22 +111,20 @@ tidy_strip() {
>
> local binary strip_flags
> find . -type f -perm -u+w -print0 2>/dev/null | while IFS= read -rd '' binary ; do
> - case "$(file -bi "$binary")" in
> - *application/x-sharedlib*) # Libraries (.so)
> + 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";;
> - *application/x-archive*) # Libraries (.a)
> - strip_flags="$STRIP_STATIC";;
> - *application/x-object*)
> - case "$binary" in
> - *.ko) # Kernel module
> - strip_flags="$STRIP_SHARED";;
> - *)
> - continue;;
> - esac;;
> - *application/x-executable*) # Binaries
> + *Type:*'EXEC (Executable file)'*) # Binaries
> strip_flags="$STRIP_BINARIES";;
> - *application/x-pie-executable*) # Relocatable binaries
> - strip_flags="$STRIP_SHARED";;
> + *Type:*'REL (Relocatable file)'*) # Libraries (.a) or objects
> + if ar t "$binary" &>/dev/null; then # Libraries (.a)
> + strip_flags="$STRIP_STATIC"
> + elif [[ $binary = *'.ko' ]]; then # Kernel module
> + strip_flags="$STRIP_SHARED"
> + else
> + continue
> + fi
> + ;;
> *)
> continue ;;
> esac
>
More information about the pacman-dev
mailing list