@@ -186,73 +186,67 @@ def _extract_tar(archive_path: pathlib.Path, prefix: str, target_dir: pathlib.Pa
186186
187187GLIBC_VERSION = "2.29"
188188GLIBC_ROOT = pathlib .Path (f"/tmp/glibc-install-{ GLIBC_VERSION } " )
189- GLIBC_LOADER = GLIBC_ROOT / "lib" / "ld-linux-x86-64.so.2"
190189GLIBC_LIBDIR = GLIBC_ROOT / "lib"
190+ GLIBC_LOADER_CANDIDATES = [
191+ GLIBC_LIBDIR / "ld-2.29.so" ,
192+ GLIBC_LIBDIR / "ld-linux-x86-64.so.2" ,
193+ ]
194+ GLIBC_LOADER = next ((p for p in GLIBC_LOADER_CANDIDATES if p .exists ()), None )
191195GLIBC_REEXEC_GUARD = "QNN_GLIBC_REEXEC"
192196
193- MINIMUM_LIBC_VERSION = 2.29
194-
195- GLIBC_CUSTOM = "/tmp/glibc-install-2.29/lib/libc.so.6"
197+ MINIMUM_LIBC_VERSION = "2.29"
198+ GLIBC_CUSTOM = str (GLIBC_LIBDIR / "libc.so.6" )
196199
197200REQUIRED_LIBC_LIBS = [
198- "/lib/x86_64-linux-gnu/libc.so.6" ,
201+ GLIBC_CUSTOM ,
199202 "/lib64/libc.so.6" ,
203+ "/lib/x86_64-linux-gnu/libc.so.6" ,
200204 "/lib/libc.so.6" ,
201- GLIBC_CUSTOM ,
202205]
203206
204207
208+ def _parse_version (v : str ) -> tuple [int , int ]:
209+ parts = v .split ("." )
210+ return int (parts [0 ]), int (parts [1 ]) if len (parts ) > 1 else 0
211+
212+
205213def check_glibc_exist_and_validate () -> bool :
206214 """
207- Check if users have glibc installed.
215+ Check if users have glibc installed (system or custom in /tmp) .
208216 """
209- exists = False
210- for path in REQUIRED_LIBC_LIBS :
217+ GLIBC_CUSTOM = f"/tmp/glibc-install-{ GLIBC_VERSION } /lib/libc.so.6"
218+ candidates = [GLIBC_CUSTOM , "/lib64/libc.so.6" , "/lib/x86_64-linux-gnu/libc.so.6" ]
219+
220+ for path in candidates :
221+ if not pathlib .Path (path ).exists ():
222+ continue
211223 try :
212224 output = subprocess .check_output (
213225 [path , "--version" ], stderr = subprocess .STDOUT
214226 )
215- output = output .decode ().split ("\n " )[0 ]
216- logger .debug (f"[QNN] glibc version for path { path } is: { output } " )
217- match = re .search (r"version (\d+\.\d+)" , output )
227+ first_line = output .decode ().split ("\n " , 1 )[0 ]
228+ logger .debug (f"[QNN] glibc version for path { path } is: { first_line } " )
229+
230+ match = re .search (r"version (\d+\.\d+)" , first_line )
218231 if match :
219232 version = match .group (1 )
220- if float (version ) >= MINIMUM_LIBC_VERSION :
221- logger .debug (f"[QNN] glibc version is { version } ." )
222- exists = True
233+ if _parse_version (version ) >= _parse_version (MINIMUM_LIBC_VERSION ):
234+ logger .info (f"[QNN] Using glibc { version } from { path } " )
223235 return True
224236 else :
225237 logger .error (
226- f"[QNN] glibc version is too low. The minimum libc version is { MINIMUM_LIBC_VERSION } Please install glibc following the commands below."
238+ f"[QNN] glibc version { version } is too low at { path } . "
239+ f"Need >= { MINIMUM_LIBC_VERSION } ."
227240 )
228241 else :
229- logger .error ("[QNN] glibc version not found." )
230-
231- except Exception :
232- continue
242+ logger .error (f"[QNN] Could not parse glibc version from { first_line } " )
243+ except Exception as e :
244+ logger .error (f"[QNN] Failed to check { path } : { e } " )
233245
234- if not exists :
235- logger .error (
236- r""""
237- [QNN] glibc not found or the version is too low. Please install glibc following the commands below.
238- Ubuntu/Debian:
239- sudo apt update
240- sudo apt install libc6
241-
242- Fedora/Red Hat:
243- sudo dnf install glibc
244-
245- Arch Linux:
246- sudo pacman -S glibc
247-
248- Also please make sure the glibc version is >= MINIMUM_LIBC_VERSION. You can verify the glibc version by running the following command:
249- Option 1:
250- ldd --version
251- Option 2:
252- /path/to/libc.so.6 --version
253- """
254- )
255- return exists
246+ logger .error (
247+ f"[QNN] glibc not found or too old. Minimum required: { MINIMUM_LIBC_VERSION } ."
248+ )
249+ return False
256250
257251
258252def _check_tmp_glibc () -> bool :
0 commit comments