@@ -254,123 +254,23 @@ def _extract_tar(archive_path: pathlib.Path, prefix: str, target_dir: pathlib.Pa
254254GLIBC_REEXEC_GUARD = "QNN_GLIBC_REEXEC"
255255
256256
257- def _parse_ver_tuple (s : str ) -> Tuple [int , int ]:
258- parts = re .findall (r"\d+" , s )
259- return (int (parts [0 ]), int (parts [1 ])) if len (parts ) >= 2 else (0 , 0 )
260-
261-
262- def _detect_glibc_version () -> Optional [Tuple [int , int ]]:
263- for path in REQUIRED_LIBC_LIBS :
264- try :
265- out = subprocess .check_output ([path , "--version" ], stderr = subprocess .STDOUT )
266- first = out .decode (errors = "ignore" ).split ("\n " , 1 )[0 ]
267- m = re .search (r"version\s+(\d+\.\d+)" , first , re .IGNORECASE )
268- if m :
269- vt = _parse_ver_tuple (m .group (1 ))
270- logger .info ("[glibc] Found %s version %s" , path , vt )
271- return vt
272- except Exception as e :
273- logger .info ("[glibc] Skipped %s (%s)" , path , e )
274- return None
275-
276-
277- def _install_glibc_234 ():
278- """Download and build glibc GLIBC_VERSION into /tmp/glibc-{GLIBC_VERSION} if missing."""
279- if GLIBC_LOADER .exists ():
280- logger .info ("[glibc] Already installed at %s" , GLIBC_ROOT )
281- return
282-
283- logger .info (f"[glibc] Installing glibc { GLIBC_VERSION } into %s ..." , GLIBC_ROOT )
284- # url = "https://ftp.gnu.org/gnu/libc/glibc-2.34.tar.xz"
285- # url = "https://ftp.gnu.org/gnu/libc/glibc-2.36.tar.xz"
286- url = f"https://ftp.gnu.org/gnu/libc/glibc-{ GLIBC_VERSION } .tar.xz"
257+ def _check_tmp_glibc () -> bool :
258+ """Check if glibc in /tmp was installed correctly and log its version."""
259+ libc_path = pathlib .Path (f"/tmp/glibc-{ GLIBC_VERSION } /lib/libc.so.6" )
260+ if not libc_path .exists ():
261+ logger .error ("[glibc] Expected glibc at %s but file not found" , libc_path )
262+ return False
287263
288- with tempfile .TemporaryDirectory () as tmpdir :
289- tarball = pathlib .Path (tmpdir ) / f"glibc-{ GLIBC_VERSION } .tar.xz"
290- logger .info ("[glibc] Downloading %s" , url )
291- urllib .request .urlretrieve (url , tarball )
292- logger .info ("[glibc] Downloaded %s" , tarball )
293-
294- logger .info ("[glibc] Extracting source..." )
295- with tarfile .open (tarball , "r:xz" ) as tf :
296- tf .extractall (path = tmpdir )
297-
298- build_dir = pathlib .Path (tmpdir ) / "glibc-build"
299- os .makedirs (build_dir , exist_ok = True )
300-
301- logger .info ("[glibc] Configuring build..." )
302- env = os .environ .copy ()
303-
304- # Remove LD_LIBRARY_PATH to satisfy configure checks
305- env .pop ("LD_LIBRARY_PATH" , None )
306-
307- # Allow warnings (disable -Werror promoted by newer GCC)
308- # Add -fcommon to avoid "multiple definition" issues on some glibc versions
309- env ["CFLAGS" ] = (
310- "-O2 -fPIC -fcommon "
311- "-Wno-error=array-parameter "
312- "-Wno-error=stringop-overflow "
313- "-Wno-error"
314- )
315- env ["CC" ] = "gcc"
316-
317- # Configure
318- cmd = [f"../glibc-{ GLIBC_VERSION } /configure" , f"--prefix={ GLIBC_ROOT } " ]
319- logger .info ("[glibc] Running: %s" , " " .join (cmd ))
320- subprocess .check_call (cmd , cwd = build_dir , env = env )
321-
322- # Build
323- cmd = ["make" , "-j" , str (os .cpu_count ()), "CFLAGS=" + env ["CFLAGS" ]]
324- logger .info ("[glibc] Running: %s" , " " .join (cmd ))
325- subprocess .check_call (cmd , cwd = build_dir , env = env )
326-
327- # Install
328- cmd = ["make" , "install" ]
329- logger .info ("[glibc] Running: %s" , " " .join (cmd ))
330- logger .info (f"[glibc] Installing into /tmp/glibc-{ GLIBC_VERSION } ..." )
331- subprocess .check_call (cmd , cwd = build_dir , env = env )
332- logger .info ("[glibc] Installation complete" )
333-
334- if GLIBC_LOADER .exists ():
335- logger .info (
336- f"[glibc] Successfully installed glibc { GLIBC_VERSION } at %s" , GLIBC_ROOT
337- )
338- else :
339- logger .error (
340- "[glibc] Install finished but loader not found at %s" , GLIBC_LOADER
264+ try :
265+ out = subprocess .check_output (
266+ [str (libc_path ), "--version" ], stderr = subprocess .STDOUT
341267 )
342-
343-
344- def _reexec_with_new_glibc_if_needed (min_required = (2 , 29 )):
345- if os .environ .get (GLIBC_REEXEC_GUARD ) == "1" :
346- logger .debug ("[glibc] Already re-executed once; skipping loop." )
347- return
348-
349- vt = _detect_glibc_version ()
350- if vt is None :
351- logger .warn ("[glibc] Could not detect system glibc version." )
352- elif vt < min_required :
353- logger .warn ("[glibc] System glibc %s < required %s" , vt , min_required )
354- else :
355- logger .info ("[glibc] System glibc %s >= required %s" , vt , min_required )
356- return
357-
358- _install_glibc_234 ()
359- if not GLIBC_LOADER .exists ():
360- logger .error ("[glibc] Loader still missing at %s" , GLIBC_LOADER )
361- return
362-
363- argv = [
364- str (GLIBC_LOADER ),
365- "--library-path" ,
366- str (GLIBC_LIBDIR ),
367- sys .executable ,
368- ] + sys .argv
369- env = os .environ .copy ()
370- env [GLIBC_REEXEC_GUARD ] = "1"
371-
372- logger .warn ("[glibc] Re-executing under new loader: %s" , argv )
373- os .execvpe (str (GLIBC_LOADER ), argv , env )
268+ first_line = out .decode (errors = "ignore" ).split ("\n " , 1 )[0 ]
269+ logger .info ("[glibc] Found custom glibc at %s: %s" , libc_path , first_line )
270+ return True
271+ except Exception as e :
272+ logger .error ("[glibc] Failed to run %s --version: %s" , libc_path , e )
273+ return False
374274
375275
376276####################
@@ -575,7 +475,10 @@ def install_qnn_sdk() -> bool:
575475 """
576476 logger .info ("[QNN] Starting SDK installation" )
577477 # Re-exec with glibc 2.36 if needed.
578- _reexec_with_new_glibc_if_needed ()
478+ # Just check that pre-installed glibc is present and valid
479+ if not _check_tmp_glibc ():
480+ logger .error ("[glibc] Pre-installed glibc check failed. Exiting early." )
481+ return False
579482
580483 if _ensure_libcxx_stack ():
581484 if _ensure_qnn_sdk_lib ():
0 commit comments