Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.6)

project (elfin)

set(CMAKE_CXX_STANDARD 17)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be 11, not 17

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 11)


add_subdirectory(elf elfdir)
add_subdirectory(dwarf dwarfdir)
add_subdirectory(examples examplesdir)
Comment on lines +7 to +9
Copy link

@madebr madebr Oct 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding an immediate subdirectory in the source tree as a different directory in the build directory is not necessary.
Also, optionally building the examples is nice as they are not needed when e.g. only wanting to build the library or adding libelfin as a subdirectory/subproject.

Suggested change
add_subdirectory(elf elfdir)
add_subdirectory(dwarf dwarfdir)
add_subdirectory(examples examplesdir)
option(BUILD_LIBELFIN_EXAMPLES "Build libelfin examples" ON)
add_subdirectory(elf)
add_subdirectory(dwarf)
if(BUILD_LIBELFIN_EXAMPLES)
add_subdirectory(examples)
endif()

21 changes: 21 additions & 0 deletions dwarf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Comment on lines +5 to +6
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set(dwarfH ${CMAKE_CURRENT_LIST_DIR}/dwarf++.hh)
set(dataH ${CMAKE_CURRENT_LIST_DIR}/data.hh)
set(dwarfH ${CMAKE_CURRENT_SOURCE_DIR}/dwarf++.hh)
set(dataH ${CMAKE_CURRENT_SOURCE_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})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bash is not really cross platform (it is less often available on Windows then python).
I would just use a add_custom_command with all commands from the bash script.

See conan-io/conan-center-index#3283 for an example.

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})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
target_include_directories(dwarf PUBLIC ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(dwarf PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(dwarf elf)
20 changes: 20 additions & 0 deletions dwarf/create_to_string_code.sh
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions elf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.6)

project(elf)

set(toStringInputHeader ${CMAKE_CURRENT_LIST_DIR}/data.hh)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set(toStringInputHeader ${CMAKE_CURRENT_LIST_DIR}/data.hh)
set(toStringInputHeader ${CMAKE_CURRENT_SOURCE_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}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark as the dwarf library.
I would not use bash but add these commands directly here.
See conan-io/conan-center-index#3283 again

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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dependency (or add_custom_target) should not be necessary.
As the generated source is added to the sources of the add_library, cmake knows already that the generated source is a dependency of the library and that its source should be generated first.

target_include_directories(elf PUBLIC ${CMAKE_CURRENT_LIST_DIR})
17 changes: 17 additions & 0 deletions elf/create_to_string_code.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions elf/mmap_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>

Expand Down
11 changes: 11 additions & 0 deletions elf/to_string_prototype.txt
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions examples/dump-lines.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "elf++.hh"
#include "dwarf++.hh"

#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>

Expand Down
1 change: 1 addition & 0 deletions examples/dump-sections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>

Expand Down
1 change: 1 addition & 0 deletions examples/dump-segments.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>

Expand Down
1 change: 1 addition & 0 deletions examples/dump-syms.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>

Expand Down
1 change: 1 addition & 0 deletions examples/dump-tree.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "elf++.hh"
#include "dwarf++.hh"

#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>

Expand Down
1 change: 1 addition & 0 deletions examples/find-pc.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "elf++.hh"
#include "dwarf++.hh"

#include <errno.h>
#include <fcntl.h>
#include <string>
#include <inttypes.h>
Expand Down