@@ -7,7 +7,16 @@ gatherLibraries() {
77addEnvHooks "$targetOffset" gatherLibraries
88
99isExecutable() {
10− readelf -h "$1" 2> /dev/null | grep -q '^ *Type: *EXEC\>'
10+ # For dynamically linked ELF files it would be enough to check just for the
11+ # INTERP section. However, we won't catch statically linked executables as
12+ # they only have an ELF type of EXEC but no INTERP.
13+ #
14+ # So what we do here is just check whether *either* the ELF type is EXEC
15+ # *or* there is an INTERP section. This also catches position-independent
16+ # executables, as they typically have an INTERP section but their ELF type
17+ # is DYN.
18+ LANG=C readelf -h -l "$1" 2> /dev/null \
19+ | grep -q '^ *Type: *EXEC\>\|^ *INTERP\>'
1120}
1221
1322# We cache dependencies so that we don't need to search through all of them on
@@ -157,7 +166,7 @@ autoPatchelf() {
157166 isELF "$file" || continue
158167 if isExecutable "$file"; then
159168 # Skip if the executable is statically linked.
160− readelf -l "$file" | grep -q "^ *INTERP\\>" || continue
169+ LANG=C readelf -l "$file" | grep -q "^ *INTERP\\>" || continue
161170 fi
162171 autoPatchelfFile "$file"
163172 done < <(find "$prefix" -type f -print0)