From 1f6f8da0d3441095740918d501e9d3738e4ede47 Mon Sep 17 00:00:00 2001 From: Junghee Lim Date: Wed, 22 May 2024 17:52:13 -0400 Subject: [PATCH 1/2] Avoid generating `_start` symbol for entry-point 0 in shared libraries --- CHANGELOG.md | 2 ++ src/datalog/binary/elf/symbolization.dl | 2 ++ tests/misc_test.py | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 695fdf27..bef45c43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,8 @@ * Add alignment for x86-64 instructions that require explicitly aligned memory (e.g., some SIMD instructions) * Update capstone version from 4.0.1 to 5.0.1 +* Avoid generating `_start` symbol when the entry-point is 0 in shared + libraries # 1.8.0 diff --git a/src/datalog/binary/elf/symbolization.dl b/src/datalog/binary/elf/symbolization.dl index 4786f90c..23c4dcc3 100644 --- a/src/datalog/binary/elf/symbolization.dl +++ b/src/datalog/binary/elf/symbolization.dl @@ -136,6 +136,8 @@ start_function(EA):- start_function(Start_location):- binary_format("ELF"), !function_symbol(Start_location,"_start"), + // Igore entry-point 0 for shared library + !(binary_type("DYN"), Start_location = 0), entry_point(Start_location). main_function(EA):- diff --git a/tests/misc_test.py b/tests/misc_test.py index 4440db2d..956b914f 100644 --- a/tests/misc_test.py +++ b/tests/misc_test.py @@ -995,5 +995,26 @@ def test_repeated_import(self): # so we don't check that here. +class ZeroEntryPointTests(unittest.TestCase): + @unittest.skipUnless( + platform.system() == "Linux", "This test is linux only." + ) + def test_zero_entry_point(self): + """ + Test a shared library that has value 0 as its entry point. + We should not create an inferred symbol for `_start` for + entry-point 0 for shared libraries. + """ + + library = Path("ex.so") + with cd(ex_asm_dir / "ex_ifunc"): + self.assertTrue(compile("gcc", "g++", "-O0 --entry 0", [])) + ir_library = disassemble(library).ir() + m = ir_library.modules[0] + + # `_start` should not exist in the module. + self.assertEqual(len(list(m.symbols_named("_start"))), 0) + + if __name__ == "__main__": unittest.main() From a2854313f1e6dcff999e9bd44992a71d099103bb Mon Sep 17 00:00:00 2001 From: Junghee Lim Date: Thu, 23 May 2024 09:59:13 -0400 Subject: [PATCH 2/2] Make the entry-point 0 issue general --- CHANGELOG.md | 3 +-- src/datalog/binary/elf/symbolization.dl | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bef45c43..009e7c7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,8 +28,7 @@ * Add alignment for x86-64 instructions that require explicitly aligned memory (e.g., some SIMD instructions) * Update capstone version from 4.0.1 to 5.0.1 -* Avoid generating `_start` symbol when the entry-point is 0 in shared - libraries +* Avoid generating `_start` symbol when the entry-point address is not a code block. # 1.8.0 diff --git a/src/datalog/binary/elf/symbolization.dl b/src/datalog/binary/elf/symbolization.dl index 23c4dcc3..0afd0d9f 100644 --- a/src/datalog/binary/elf/symbolization.dl +++ b/src/datalog/binary/elf/symbolization.dl @@ -136,9 +136,8 @@ start_function(EA):- start_function(Start_location):- binary_format("ELF"), !function_symbol(Start_location,"_start"), - // Igore entry-point 0 for shared library - !(binary_type("DYN"), Start_location = 0), - entry_point(Start_location). + entry_point(Start_location), + code(Start_location). main_function(EA):- binary_format("ELF"),