aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/elf_parser.cc59
-rw-r--r--test/elf_parser/Makefile12
-rw-r--r--test/elf_parser/test.cc7
3 files changed, 78 insertions, 0 deletions
diff --git a/test/elf_parser.cc b/test/elf_parser.cc
new file mode 100644
index 0000000..6f16639
--- /dev/null
+++ b/test/elf_parser.cc
@@ -0,0 +1,59 @@
+#include "elf_parser.h"
+
+#include <cstddef>
+#include <cstdio>
+
+#include <elf.h>
+
+#include "elf_parser/libtest-32.h"
+#include "elf_parser/libtest-64.h"
+
+void dump_dynsyms(const unsigned char* bytes, size_t len) {
+ auto elf = elf::parse(bytes, len);
+
+ elf->dynsyms([](const char* name, char type, char bind) { // NOLINT
+ const char* bind_str = "<unnown>";
+ switch (bind) {
+ case STB_GLOBAL:
+ bind_str = "GLOBAL";
+ break;
+ case STB_LOCAL:
+ bind_str = "LOCAL";
+ break;
+ case STB_WEAK:
+ bind_str = "WEAK";
+ break;
+ default:
+ break;
+ }
+
+ const char* type_str = "<unknown>";
+ switch (type) {
+ case STT_NOTYPE:
+ type_str = "NOTYPE";
+ break;
+ case STT_FUNC:
+ type_str = "FUNC";
+ break;
+ case STT_OBJECT:
+ type_str = "OBJECT";
+ break;
+ case STT_SECTION:
+ type_str = "SECTION";
+ break;
+ case STT_FILE:
+ type_str = "FILE";
+ break;
+ default:
+ break;
+ }
+
+ printf("syms type: %10s bind: %10s name: %s\n", type_str, bind_str, name);
+ return true;
+ });
+}
+
+int main() {
+ dump_dynsyms(libtest_32_so, libtest_32_so_len);
+ dump_dynsyms(libtest_64_so, libtest_64_so_len);
+}
diff --git a/test/elf_parser/Makefile b/test/elf_parser/Makefile
new file mode 100644
index 0000000..ea726bd
--- /dev/null
+++ b/test/elf_parser/Makefile
@@ -0,0 +1,12 @@
+all: libtest-32.h libtest-64.h
+
+libtest-%.h: libtest-%.so
+ xxd -i $^ > $@
+ sed -i 's#^unsigned#// NOLINTNEXTLINE\nunsigned#' $@
+ clang-format -i $@
+
+libtest-%.so: test.cc
+ $(CC) -m$* -shared -fPIC -o $@ $^
+
+clean:
+ $(RM) libtest-*.so libtest-*.h
diff --git a/test/elf_parser/test.cc b/test/elf_parser/test.cc
new file mode 100644
index 0000000..7cc71dd
--- /dev/null
+++ b/test/elf_parser/test.cc
@@ -0,0 +1,7 @@
+extern "C" int exported_func_c(int x) {
+ return x + 1;
+}
+
+int exported_func_cpp(int x) {
+ return x + 1;
+}