Skip to content

Commit

Permalink
Merge branch 'junghee/entry-point0' into 'main'
Browse files Browse the repository at this point in the history
Avoid generating `_start` symbol for entry-point 0 in shared libraries

Closes debloating/dykondo#42

See merge request rewriting/ddisasm!1207
  • Loading branch information
aeflores committed May 28, 2024
2 parents 8b2dfea + a285431 commit 9241d9c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +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 address is not a code block.

# 1.8.0

Expand Down
3 changes: 2 additions & 1 deletion src/datalog/binary/elf/symbolization.dl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ start_function(EA):-
start_function(Start_location):-
binary_format("ELF"),
!function_symbol(Start_location,"_start"),
entry_point(Start_location).
entry_point(Start_location),
code(Start_location).

main_function(EA):-
binary_format("ELF"),
Expand Down
21 changes: 21 additions & 0 deletions tests/misc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 9241d9c

Please sign in to comment.