diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..578c203 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.6) + +project (elfin) + +set(CMAKE_CXX_STANDARD 17) + +add_subdirectory(elf elfdir) +add_subdirectory(dwarf dwarfdir) +add_subdirectory(examples examplesdir) diff --git a/dwarf/CMakeLists.txt b/dwarf/CMakeLists.txt new file mode 100644 index 0000000..2f27221 --- /dev/null +++ b/dwarf/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.6) + +project(dwarf) + +set(dwarfH ${CMAKE_CURRENT_LIST_DIR}/dwarf++.hh) +set(dataH ${CMAKE_CURRENT_LIST_DIR}/data.hh) +set(to_string_src ${CMAKE_CURRENT_BINARY_DIR}/to_string.cc) +set(configured_to_string_script ${CMAKE_CURRENT_BINARY_DIR}/create_to_string_code.sh) + +configure_file(create_to_string_code.sh ${configured_to_string_script}) + +add_custom_command( + OUTPUT ${to_string_src} + COMMAND bash ${configured_to_string_script} ${dwarfH} ${dataH} ${to_string_src}) +add_custom_target(to_string_target DEPENDS ${to_string_src}) + +add_library(dwarf dwarf.cc cursor.cc die.cc value.cc abbrev.cc + expr.cc rangelist.cc line.cc attrs.cc + die_str_map.cc elf.cc ${to_string_src}) +target_include_directories(dwarf PUBLIC ${CMAKE_CURRENT_LIST_DIR}) +target_link_libraries(dwarf elf) diff --git a/dwarf/create_to_string_code.sh b/dwarf/create_to_string_code.sh new file mode 100644 index 0000000..72c02c6 --- /dev/null +++ b/dwarf/create_to_string_code.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# $1 is dwarf++.hh +# $2 is data.hh +# $3 is to_string.cc + +( +echo "// Automatically generated by make at $(date)" +echo "// DO NOT EDIT" +echo +echo '#include "internal.hh"' +echo +echo DWARFPP_BEGIN_NAMESPACE +echo + +python3 ${CMAKE_CURRENT_LIST_DIR}/../elf/enum-print.py < $1 +python3 ${CMAKE_CURRENT_LIST_DIR}/../elf/enum-print.py -s _ -u --hex -x hi_user -x lo_user < $2 + +echo DWARFPP_END_NAMESPACE +) > $3 diff --git a/elf/CMakeLists.txt b/elf/CMakeLists.txt new file mode 100644 index 0000000..3ff6a6b --- /dev/null +++ b/elf/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.6) + +project(elf) + +set(toStringInputHeader ${CMAKE_CURRENT_LIST_DIR}/data.hh) +set(to_string_src ${CMAKE_CURRENT_BINARY_DIR}/to_string.cc) +set(configured_to_string_script ${CMAKE_CURRENT_BINARY_DIR}/create_to_string_code.sh) + +configure_file(create_to_string_code.sh ${configured_to_string_script}) + +add_custom_command( + OUTPUT ${to_string_src} + COMMAND bash ${configured_to_string_script} ${toStringInputHeader} ${to_string_src}) +add_custom_target(elf_to_string_target DEPENDS ${to_string_src}) +add_library(elf elf.cc mmap_loader.cc ${to_string_src}) +add_dependencies(elf elf_to_string_target) +target_include_directories(elf PUBLIC ${CMAKE_CURRENT_LIST_DIR}) diff --git a/elf/create_to_string_code.sh b/elf/create_to_string_code.sh new file mode 100644 index 0000000..2bf053e --- /dev/null +++ b/elf/create_to_string_code.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +( +echo "// Automatically generated by make at $(date)" +echo "// DO NOT EDIT" +echo +echo '#include "data.hh"' +echo '#include "to_hex.hh"' +echo +echo 'ELFPP_BEGIN_NAMESPACE' +echo + +python3 ${CMAKE_CURRENT_LIST_DIR}/enum-print.py -u --hex --no-type --mask shf --mask pf \ + -x loos -x hios -x loproc -x hiproc < $1 + +echo ELFPP_END_NAMESPACE +) > $2 diff --git a/elf/mmap_loader.cc b/elf/mmap_loader.cc index 69d8acb..875d7bd 100644 --- a/elf/mmap_loader.cc +++ b/elf/mmap_loader.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include diff --git a/elf/to_string_prototype.txt b/elf/to_string_prototype.txt new file mode 100644 index 0000000..8110602 --- /dev/null +++ b/elf/to_string_prototype.txt @@ -0,0 +1,11 @@ +// Automatically generated by make at ${currentTime} +// DO NOT EDIT + +#include "data.hh" +#include "to_hex.hh" + +ELFPP_BEGIN_NAMESPACE + +${to_string_cc_contents} + +ELFPP_END_NAMESPACE diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..09f77a6 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.6) + +project(libelfinexamples) + +add_executable(dump-lines dump-lines.cc) +target_link_libraries(dump-lines dwarf) + +add_executable(dump-sections dump-sections.cc) +target_link_libraries(dump-sections dwarf) + +add_executable(dump-segments dump-segments.cc) +target_link_libraries(dump-segments dwarf) + +add_executable(dump-syms dump-syms.cc) +target_link_libraries(dump-syms dwarf) + +add_executable(dump-tree dump-tree.cc) +target_link_libraries(dump-tree dwarf) + +add_executable(find-pc find-pc.cc) +target_link_libraries(find-pc dwarf) diff --git a/examples/dump-lines.cc b/examples/dump-lines.cc index ec58be1..9fed1fa 100644 --- a/examples/dump-lines.cc +++ b/examples/dump-lines.cc @@ -1,6 +1,7 @@ #include "elf++.hh" #include "dwarf++.hh" +#include #include #include diff --git a/examples/dump-sections.cc b/examples/dump-sections.cc index 12e7569..22526ec 100644 --- a/examples/dump-sections.cc +++ b/examples/dump-sections.cc @@ -2,6 +2,7 @@ #include #include +#include #include #include diff --git a/examples/dump-segments.cc b/examples/dump-segments.cc index f9e07d3..4c6319f 100644 --- a/examples/dump-segments.cc +++ b/examples/dump-segments.cc @@ -2,6 +2,7 @@ #include #include +#include #include #include diff --git a/examples/dump-syms.cc b/examples/dump-syms.cc index e7c2c3b..af7f484 100644 --- a/examples/dump-syms.cc +++ b/examples/dump-syms.cc @@ -2,6 +2,7 @@ #include #include +#include #include #include diff --git a/examples/dump-tree.cc b/examples/dump-tree.cc index 57d2b70..8bf2a63 100644 --- a/examples/dump-tree.cc +++ b/examples/dump-tree.cc @@ -1,6 +1,7 @@ #include "elf++.hh" #include "dwarf++.hh" +#include #include #include diff --git a/examples/find-pc.cc b/examples/find-pc.cc index dc40b85..2e324fc 100644 --- a/examples/find-pc.cc +++ b/examples/find-pc.cc @@ -1,6 +1,7 @@ #include "elf++.hh" #include "dwarf++.hh" +#include #include #include #include