@ -21,7 +21,7 @@ import shutil
import subprocess
import subprocess
import typing as T
import typing as T
from . . mesonlib import OrderedSet
from . . mesonlib import OrderedSet , generate_list
SHT_STRTAB = 3
SHT_STRTAB = 3
DT_NEEDED = 1
DT_NEEDED = 1
@ -243,14 +243,14 @@ class Elf(DataSizes):
if e . d_tag == 0 :
if e . d_tag == 0 :
break
break
def print_section_names ( self ) - > None :
@generate_list
def get_section_names ( self ) - > T . Generator [ str , None , None ] :
section_names = self . sections [ self . e_shstrndx ]
section_names = self . sections [ self . e_shstrndx ]
for i in self . sections :
for i in self . sections :
self . bf . seek ( section_names . sh_offset + i . sh_name )
self . bf . seek ( section_names . sh_offset + i . sh_name )
name = self . read_str ( )
yield self . read_str ( ) . decode ( )
print ( name . decode ( ) )
def prin t_soname( self ) - > None :
def ge t_soname( self ) - > T . Optional [ str ] :
soname = None
soname = None
strtab = None
strtab = None
for i in self . dynamic :
for i in self . dynamic :
@ -259,10 +259,9 @@ class Elf(DataSizes):
if i . d_tag == DT_STRTAB :
if i . d_tag == DT_STRTAB :
strtab = i
strtab = i
if soname is None or strtab is None :
if soname is None or strtab is None :
print ( " This file does not have a soname " )
return None
return
self . bf . seek ( strtab . val + soname . val )
self . bf . seek ( strtab . val + soname . val )
print ( self . read_str ( ) )
return self . read_str ( ) . decode ( )
def get_entry_offset ( self , entrynum : int ) - > T . Optional [ int ] :
def get_entry_offset ( self , entrynum : int ) - > T . Optional [ int ] :
sec = self . find_section ( b ' .dynstr ' )
sec = self . find_section ( b ' .dynstr ' )
@ -273,33 +272,28 @@ class Elf(DataSizes):
return res
return res
return None
return None
def prin t_rpath( self ) - > None :
def ge t_rpath( self ) - > T . Optional [ str ] :
offset = self . get_entry_offset ( DT_RPATH )
offset = self . get_entry_offset ( DT_RPATH )
if offset is None :
if offset is None :
print ( " This file does not have an rpath. " )
return None
else :
self . bf . seek ( offset )
self . bf . seek ( offset )
return self . read_str ( ) . decode ( )
print ( self . read_str ( ) )
def prin t_runpath( self ) - > None :
def ge t_runpath( self ) - > T . Optional [ str ] :
offset = self . get_entry_offset ( DT_RUNPATH )
offset = self . get_entry_offset ( DT_RUNPATH )
if offset is None :
if offset is None :
print ( " This file does not have a runpath. " )
return None
else :
self . bf . seek ( offset )
self . bf . seek ( offset )
return self . read_str ( ) . decode ( )
print ( self . read_str ( ) )
def print_deps ( self ) - > None :
@generate_list
def get_deps ( self ) - > T . Generator [ str , None , None ] :
sec = self . find_section ( b ' .dynstr ' )
sec = self . find_section ( b ' .dynstr ' )
deps = [ ]
for i in self . dynamic :
for i in self . dynamic :
if i . d_tag == DT_NEEDED :
if i . d_tag == DT_NEEDED :
deps . append ( i )
offset = sec . sh_offset + i . val
for i in deps :
self . bf . seek ( offset )
offset = sec . sh_offset + i . val
yield self . read_str ( ) . decode ( )
self . bf . seek ( offset )
name = self . read_str ( )
print ( name )
def fix_deps ( self , prefix : bytes ) - > None :
def fix_deps ( self , prefix : bytes ) - > None :
sec = self . find_section ( b ' .dynstr ' )
sec = self . find_section ( b ' .dynstr ' )
@ -391,11 +385,9 @@ class Elf(DataSizes):
return None
return None
def fix_elf ( fname : str , rpath_dirs_to_remove : T . Set [ bytes ] , new_rpath : T . Optional [ bytes ] , verbose : bool = True ) - > None :
def fix_elf ( fname : str , rpath_dirs_to_remove : T . Set [ bytes ] , new_rpath : T . Optional [ bytes ] , verbose : bool = True ) - > None :
with Elf ( fname , verbose ) as e :
if new_rpath is not None :
if new_rpath is None :
with Elf ( fname , verbose ) as e :
e . print_rpath ( )
# note: e.get_rpath() and e.get_runpath() may be useful
e . print_runpath ( )
else :
e . fix_rpath ( rpath_dirs_to_remove , new_rpath )
e . fix_rpath ( rpath_dirs_to_remove , new_rpath )
def get_darwin_rpaths_to_remove ( fname : str ) - > T . List [ str ] :
def get_darwin_rpaths_to_remove ( fname : str ) - > T . List [ str ] :