Skip to content

Commit 63ffd9b

Browse files
committed
working linker check
1 parent fde12a7 commit 63ffd9b

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

src/penguin/config_patchers.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,10 +1642,6 @@ class LinkerSymbolSearch(PatchGenerator):
16421642
key->value mappings from libraries exporting some common nvram
16431643
defaults symbols ("Nvrams", "router_defaults") - add these to our
16441644
nvram config if we have any.
1645-
1646-
TODO: if we find multiple nvram source files here, we should generate multiple patches.
1647-
Then we should consider these during search. For now we just take non-conflicting values
1648-
from largest to smallest source files. More realistic might be to try each file individually.
16491645
'''
16501646

16511647
def __init__(self, library_info, archid):
@@ -1659,11 +1655,17 @@ def generate(self, patches):
16591655
if not len(sources):
16601656
return
16611657
linkers_without_preload = []
1658+
linkers = self.linker_paths.copy()
1659+
16621660
for file in sources.keys():
16631661
if file in self.linker_paths.keys():
1664-
self.linker_paths.pop('file')
1662+
self.linker_paths.pop(file)
16651663
if not ("_dl_preload" in sources[file] or "handle_ld_preload" in sources[file]):
16661664
linkers_without_preload.append(file)
1667-
print(linkers_without_preload)
1668-
1669-
1665+
for x in sources[file]:
1666+
if "GLIBC_" in x:
1667+
linkers_without_preload.remove(file)
1668+
break
1669+
if not len(linkers_without_preload):
1670+
return
1671+
logger.critical(f"The following linkers are missing PRELOAD capabilites: {linkers_without_preload} out of {linkers.keys()}")

src/penguin/gen_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ def run_static_analyses(self, output_dir, extracted_dir, static_dir_name="static
9494
# If we have results, store on disk. Always store in results dict, even if empty
9595
if this_result:
9696
with open(results_dir / f"{analysis.__name__}.yaml", "w") as f:
97+
if analysis == STATIC.ArchId:
98+
this_result = this_result[0]
9799
yaml.dump(this_result, f)
98100

99101
return results

src/penguin/static_analyses.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,17 @@ def run(self, extracted_fs, prior_results):
102102
logger.warning(f"Failed to parse ELF file {path}: {e}. Ignoring")
103103
continue
104104
info = arch_filter(ef)
105+
for segment in ef.iter_segments():
106+
try:
107+
name = segment.get_interp_name()
108+
if name is not None:
109+
loaders[name] = loaders.get(name, 0) + 1
110+
except AttributeError:
111+
continue
105112
if info.bits is None or info.arch is None:
106113
arch_counts["unknown"] += 1
107114
else:
108115
arch_counts[info.bits][info.arch] += 1
109-
# Search for PT_INTERP
110-
for segment in ef.iter_segments(type=0x3):
111-
name = segment.get_interp_name()
112-
if name is not None:
113-
loaders[name] = loaders.get(name, 0) + 1
114116

115117
# If there is at least one intel and non-intel arch,
116118
# filter out all the intel ones.
@@ -660,6 +662,7 @@ class LibrarySymbols(StaticAnalysis):
660662
def run(self, extract_dir, prior_results):
661663
self.extract_dir = extract_dir
662664
self.archend = arch_end(prior_results['ArchId'][0])
665+
self.linkers = prior_results['ArchId'][1]
663666

664667
if any([x is None for x in self.archend]):
665668
self.enabled = False
@@ -755,6 +758,7 @@ def _analyze_library(elf_path, archend):
755758

756759
symbols = {} # Symbol name -> relative(?) address
757760
nvram_data = {} # key -> value (may be empty string)
761+
758762
def _is_elf(filename):
759763
try:
760764
with open(filename, "rb") as f:

0 commit comments

Comments
 (0)