-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rearranging source directories into src/ and test/. Build libegalito.a.
The Makefile has been split into parts. There is also a "make .symlinks" option which makes links to the current build directory.
- Loading branch information
Showing
23 changed files
with
359 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# root Makefile for egalito | ||
# to change settings, see env.mk | ||
|
||
.PHONY: all src test | ||
all: src test | ||
src: | ||
$(MAKE) -C src | ||
test: | ||
$(MAKE) -C test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Setup for egalito compilation environment | ||
|
||
CC = gcc | ||
CXX = g++ | ||
GENERIC_FLAGS = -Wall -Wextra -Wno-unused-parameter -I. | ||
OPT_FLAGS = -g -O2 | ||
DEPFLAGS = -MT '$@ $(@:.o=.d)' -MMD -MP | ||
CFLAGS = -std=gnu99 $(GENERIC_FLAGS) $(OPT_FLAGS) | ||
CXXFLAGS = -std=c++11 $(GENERIC_FLAGS) $(OPT_FLAGS) | ||
CLDFLAGS = -lcapstone -Wl,-q | ||
#LDFLAGS = -lcapstone -q | ||
#LDFLAGS2 = `gcc --print-file-name=libstdc++.a` `gcc --print-file-name=libgcc.a` | ||
#LDFLAGS2 = $(shell g++ -print-search-dirs 2>&1 | grep libraries | sed 's/libraries: =/:/; s/:/ -L/g') -lstdc++ --start-group -lgcc -lgcc_eh -lc --end-group | ||
|
||
ifdef PROFILE # set PROFILE=1 to enable gprof profiling | ||
CFLAGS += -no-pie -pg | ||
CXXFLAGS += -no-pie -pg | ||
CLDFLAGS += -no-pie -pg | ||
endif | ||
|
||
P_ARCH := $(shell uname -m) | ||
ifeq (aarch64,$(P_ARCH)) | ||
CFLAGS += -DARCH_AARCH64 | ||
CXXFLAGS += -DARCH_AARCH64 | ||
BUILDDIR = build_aarch64/ | ||
else ifeq (x86_64,$(P_ARCH)) | ||
CFLAGS += -DARCH_X86_64 | ||
CXXFLAGS += -DARCH_X86_64 | ||
BUILDDIR = build_x86_64/ | ||
else | ||
$(error Unsupported platform, we only handle aarch64 and x86_64) | ||
endif | ||
CFLAGS += '-DTESTDIR="example/$(BUILDDIR)"' | ||
CXXFLAGS += '-DTESTDIR="example/$(BUILDDIR)"' | ||
|
||
ifneq (,$(wildcard /usr/lib/x86_64-linux-gnu)) | ||
GLIBCDIR = /usr/lib/x86_64-linux-gnu | ||
else ifneq (,$(wildcard /usr/lib/aarch64-linux-gnu)) | ||
GLIBCDIR = /usr/lib/aarch64-linux-gnu | ||
else ifneq (,$(wildcard /usr/lib64)) | ||
GLIBCDIR = /usr/lib64 | ||
endif | ||
#STARTFILES = $(GLIBCDIR)/crt1.o $(GLIBCDIR)/crti.o `gcc --print-file-name=crtbeginT.o` | ||
STARTFILES = $(GLIBCDIR)/crti.o `gcc --print-file-name=crtbegin.o` | ||
ENDFILES = `gcc --print-file-name=crtend.o` $(GLIBCDIR)/crtn.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
*.o | ||
*.d | ||
*.swp | ||
/depend | ||
/.symlinks | ||
/loader | ||
/egalito | ||
/libegalito.a | ||
/ex | ||
/regression/elfgen_test | ||
/regression/output/* | ||
/build_x86_64 | ||
/build_aarch64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.swp | ||
/.symlinks | ||
/itest | ||
/build_x86_64 | ||
/build_aarch64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Makefile for egalito test code | ||
|
||
include ../env.mk | ||
|
||
CFLAGS += -I ../src/ | ||
CXXFLAGS += -I ../src/ | ||
CLDFLAGS += -L ../src/$(BUILDDIR) -legalito | ||
|
||
INTEGRATION_SOURCES = $(wildcard integration/*.cpp) | ||
|
||
exe-filename = $(foreach s,$1,$(BUILDDIR)$(dir $s)$(basename $(notdir $s))) | ||
obj-filename = $(foreach s,$1,$(BUILDDIR)$(dir $s)$(basename $(notdir $s)).o) | ||
dep-filename = $(foreach s,$1,$(BUILDDIR)$(dir $s)$(basename $(notdir $s)).d) | ||
|
||
SOURCES = $(INTEGRATION_SOURCES) | ||
ITEST_SOURCES = $(SOURCES) $(INTEGRATION_SOURCES) | ||
ITEST_OBJECTS = $(call obj-filename,$(ITEST_SOURCES)) | ||
ALL_SOURCES = $(sort $(ITEST_SOURCES)) | ||
ALL_OBJECTS = $(call obj-filename,$(ALL_SOURCES)) | ||
|
||
BUILDTREE = $(sort $(dir $(ALL_OBJECTS))) | ||
|
||
ITEST = $(BUILDDIR)itest | ||
|
||
OUTPUTS = $(ITEST) | ||
|
||
# Default target | ||
.PHONY: all | ||
all: $(ITEST) .symlinks | ||
|
||
$(ALL_OBJECTS): | $(BUILDTREE) | ||
$(BUILDTREE): | ||
@mkdir -p $@ | ||
|
||
.symlinks: $(OUTPUTS) | ||
@echo making symlinks... | ||
@ln -sf $(BUILDDIR)itest | ||
@touch .symlinks | ||
|
||
# Dependencies | ||
DEPEND_FILES = $(call dep-filename,$(ALL_SOURCES)) | ||
-include $(DEPEND_FILES) | ||
|
||
# Rules | ||
$(BUILDDIR)%.o: %.s | ||
$(CC) -fPIC -c $< -o $@ | ||
$(BUILDDIR)%.o: %.S | ||
$(CC) -fPIC $(DEPFLAGS) -c $< -o $@ | ||
$(BUILDDIR)%.o: %.c | ||
$(CC) $(CFLAGS) $(DEPFLAGS) -DDEBUG_GROUP=$(shell echo $< | perl -ne 'm|^(\w+)/|g;print lc($$1)') -c -o $@ $< | ||
$(BUILDDIR)%.o: %.cpp | ||
$(CXX) $(CXXFLAGS) $(DEPFLAGS) -DDEBUG_GROUP=$(shell echo $< | perl -ne 'm|^(\w+)/|g;print lc($$1)') -c -o $@ $< | ||
|
||
# Programs and libraries | ||
$(ITEST): $(ITEST_OBJECTS) | ||
$(CXX) $(CXXFLAGS) -o $@ $^ $(CLDFLAGS) | ||
|
||
# Other targets | ||
.PHONY: clean | ||
clean: | ||
-rm -rf $(BUILDDIR) .symlinks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.swp | ||
/build_x86_64 | ||
/build_aarch64 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "libc_resolve.h" | ||
#include "jumptable.h" | ||
|
||
int main() { | ||
LibcResolve::run(); | ||
JumpTableIntegration::run(); | ||
JumpTableIntegration::run2(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#include <iostream> | ||
#include "jumptable.h" | ||
#include "analysis/jumptable.h" | ||
#include "conductor/conductor.h" | ||
#include "log/registry.h" | ||
|
||
void JumpTableIntegration::run() { | ||
GroupRegistry::getInstance()->muteAllSettings(); | ||
//GroupRegistry::getInstance()->applySetting("disasm", 9); | ||
//GroupRegistry::getInstance()->applySetting("analysis", 9); | ||
|
||
try { | ||
ElfMap elf(TESTDIR "jumptable"); | ||
|
||
Conductor conductor; | ||
conductor.parse(&elf, nullptr); | ||
|
||
auto module = conductor.getMainSpace()->getModule(); | ||
auto f = module->getChildren()->getNamed()->find("main"); | ||
if(testFunction(f, 1)) { | ||
std::cout << "TEST PASSED: found jump table in main\n"; | ||
} | ||
} | ||
catch(const char *error) { | ||
std::cout << "TEST FAILED: error: " << error << std::endl; | ||
} | ||
} | ||
|
||
void JumpTableIntegration::run2() { | ||
GroupRegistry::getInstance()->muteAllSettings(); | ||
//GroupRegistry::getInstance()->applySetting("disasm", 9); | ||
//GroupRegistry::getInstance()->applySetting("analysis", 9); | ||
|
||
try { | ||
ElfMap elf(TESTDIR "jumptable"); | ||
|
||
Conductor conductor; | ||
conductor.parseRecursive(&elf); | ||
|
||
auto libc = conductor.getLibraryList()->getLibc(); | ||
if(!libc) { | ||
std::cout << "TEST FAILED: can't locate libc.so in depends\n"; | ||
return; | ||
} | ||
|
||
auto module = libc->getElfSpace()->getModule(); | ||
struct { | ||
const char *name; | ||
int expected; | ||
} testCase[] = { | ||
{"parse_expression", 2}, | ||
{"trecurse", 0} // this has a tail-recursive call | ||
}; | ||
for(size_t i = 0; i < sizeof(testCase)/sizeof(*testCase); i ++) { | ||
auto name = testCase[i].name; | ||
auto f = module->getChildren()->getNamed()->find(name); | ||
if(f) { | ||
if(!testFunction(f, testCase[i].expected)) return; | ||
} | ||
} | ||
|
||
std::cout << "TEST PASSED: found test jump tables in libc\n"; | ||
} | ||
catch(const char *error) { | ||
std::cout << "TEST FAILED: error: " << error << std::endl; | ||
} | ||
} | ||
|
||
bool JumpTableIntegration::testFunction(Function *f, int expected) { | ||
JumpTableSearch jt; | ||
jt.search(f); | ||
|
||
if((int)jt.getTableList().size() != expected) { | ||
std::cout << "TEST FAILED: function [" | ||
<< f->getSymbol()->getName() << "]: expected " << expected | ||
<< " jump tables but found " | ||
<< jt.getTableList().size() << std::endl; | ||
return false; | ||
} | ||
|
||
auto tableList = jt.getTableList(); | ||
for(auto table : tableList) { | ||
std::cout << "found jump table in [" | ||
<< f->getSymbol()->getName() << "] at " | ||
<< std::hex << table->getAddress() << " with " | ||
<< std::dec << table->getEntries() | ||
<< " entries.\n"; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef EGALITO_INTEGRATION_JUMP_TABLE_H | ||
#define EGALITO_INTEGRATION_JUMP_TABLE_H | ||
|
||
class Function; | ||
|
||
class JumpTableIntegration { | ||
public: | ||
static void run(); | ||
static void run2(); | ||
private: | ||
static bool testFunction(Function *f, int expected); | ||
}; | ||
|
||
#endif |
Oops, something went wrong.