Skip to content

Commit 93dd323

Browse files
authored
add musl support
1 parent ad1ca3b commit 93dd323

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

Linux/file.sh

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ file() {
645645
0003)
646646
#Need to distinguish between shared library and PIE executable
647647
#Check if it has an interpreter section
648-
if extract_strings "$1" | grep -qi "^/lib.*ld\|^ld-linux\|^ld\.so" 2>/dev/null; then
648+
if extract_strings "$1" | grep -qi "^/lib.*ld\|^ld-linux\|ld-musl\|^ld\.so" 2>/dev/null; then
649649
elf_type="pie executable"
650650
else
651651
elf_type="shared object"
@@ -725,10 +725,10 @@ file() {
725725

726726
#Check for dynamic linking and interpreter (This is not always 100% Accurate)
727727
interpreter=""
728-
if extract_strings "$1" | grep -qi "^/lib.*ld\|^ld-linux\|^ld\.so" 2>/dev/null; then
728+
if extract_strings "$1" | grep -qi "^/lib.*ld\|^ld-linux\|ld-musl\|^ld\.so" 2>/dev/null; then
729729
printf ', dynamically linked'
730730
#Try to find the interpreter
731-
interpreter=$(extract_strings "$1" | grep "^/lib.*ld\|^ld-linux\|^ld\.so" | head -1 2>/dev/null)
731+
interpreter=$(extract_strings "$1" | grep "^/lib.*ld\|^ld-linux\|ld-musl\|^ld\.so" | head -1 2>/dev/null | sed 's/[^/]*\(\/.*\)/\1/')
732732
if [ -n "$interpreter" ]; then
733733
printf ', interpreter %s' "$interpreter"
734734
fi
@@ -760,6 +760,24 @@ file() {
760760
if [ "$osabi" = "SYSV" ] && [ -n "$interpreter" ]; then
761761
case "$interpreter" in
762762
*/ld-linux*) printf ', for GNU/Linux' ;;
763+
*/ld-musl*) printf ', for musl/Linux' ;;
764+
*/ld-*) printf ', for Linux' ;;
765+
esac
766+
elif [ "$osabi" = "Linux" ] && [ -n "$interpreter" ]; then
767+
case "$interpreter" in
768+
*/ld-musl*) printf ', for musl/Linux' ;;
769+
*/ld-linux*) printf ', for GNU/Linux' ;;
770+
*/ld-*) printf ', for Linux' ;;
771+
esac
772+
elif [ -n "$interpreter" ]; then
773+
# Handle other OS/ABI types
774+
case "$interpreter" in
775+
*/ld-linux*) printf ', for GNU/Linux' ;;
776+
*/ld-musl*) printf ', for musl/Linux' ;;
777+
*/ld-*) printf ', for Linux' ;;
778+
*/dyld) printf ', for macOS' ;;
779+
*/ld.so*) printf ', for BSD' ;;
780+
*/ld-elf.so*) printf ', for FreeBSD' ;;
763781
esac
764782
fi
765783

@@ -915,4 +933,4 @@ else
915933
printf 'Usage: file <filename>...\n' >&2
916934
exit 1
917935
fi
918-
#-------------------------------------------------------#
936+
#-------------------------------------------------------#

0 commit comments

Comments
 (0)