Navigation Menu

Skip to content

Commit

Permalink
Add a make target to create a release binary
Browse files Browse the repository at this point in the history
  • Loading branch information
shinh committed Mar 28, 2011
1 parent e1e81de commit 2aaf6b3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
15 changes: 9 additions & 6 deletions Makefile
@@ -1,5 +1,5 @@
PROFILE_FLAGS= GCC_EXTRA_FLAGS=
GCCFLAGS=-g -Iinclude -Wall -MMD -fno-omit-frame-pointer -O $(PROFILE_FLAGS) GCCFLAGS=-g -Iinclude -Wall -MMD -fno-omit-frame-pointer -O $(GCC_EXTRA_FLAGS)
CXXFLAGS=$(GCCFLAGS) -W -Werror CXXFLAGS=$(GCCFLAGS) -W -Werror
CFLAGS=$(GCCFLAGS) -fPIC CFLAGS=$(GCCFLAGS) -fPIC


Expand Down Expand Up @@ -31,7 +31,10 @@ endif
all: $(EXES) all: $(EXES)


profile: profile:
make clean all PROFILE_FLAGS=-pg make clean all GCC_EXTRA_FLAGS=-pg

release:
make clean all "GCC_EXTRA_FLAGS=-DNOLOG -DNDEBUG"


mach: $(MAC_TARGETS) mach: $(MAC_TARGETS)


Expand All @@ -52,13 +55,13 @@ $(MACTXTS): %.txt: %.bin
# touch $@ # touch $@


extract: extract.o fat.o extract: extract.o fat.o
$(CXX) $^ -o $@ -g -I. -W -Wall $(PROFILE_FLAGS) $(CXX) $^ -o $@ -g -I. -W -Wall $(GCC_EXTRA_FLAGS)


macho2elf: macho2elf.o mach-o.o fat.o log.o macho2elf: macho2elf.o mach-o.o fat.o log.o
$(CXX) $^ -o $@ -g $(PROFILE_FLAGS) $(CXX) $^ -o $@ -g $(GCC_EXTRA_FLAGS)


ld-mac: ld-mac.o mach-o.o fat.o log.o ld-mac: ld-mac.o mach-o.o fat.o log.o
$(CXX) $^ -o $@ -g -ldl -lpthread $(PROFILE_FLAGS) $(CXX) $^ -o $@ -g -ldl -lpthread $(GCC_EXTRA_FLAGS)


# TODO(hamaji): autotoolize? # TODO(hamaji): autotoolize?
libmac/libmac.so: libmac/mac.o libmac/libmac.so: libmac/mac.o
Expand Down
8 changes: 4 additions & 4 deletions ld-mac.cc
Expand Up @@ -90,7 +90,7 @@ class FileMap {


void addWatchDog(uintptr_t addr) { void addWatchDog(uintptr_t addr) {
bool r = maps_.insert(make_pair(addr, (SymbolMap*)NULL)).second; bool r = maps_.insert(make_pair(addr, (SymbolMap*)NULL)).second;
assert(r); CHECK(r);
} }


const char* dumpSymbol(void* p) { const char* dumpSymbol(void* p) {
Expand Down Expand Up @@ -316,7 +316,7 @@ class MachOLoader {
LOG << "will rebase: filename=" << mach.filename() LOG << "will rebase: filename=" << mach.filename()
<< ", vmaddr=" << (void*)vmaddr << ", vmaddr=" << (void*)vmaddr
<< ", last_addr=" << (void*)last_addr_ << endl; << ", last_addr=" << (void*)last_addr_ << endl;
assert(i == 0); CHECK(i == 0);
vmaddr = last_addr_; vmaddr = last_addr_;
*slide = vmaddr - seg->vmaddr; *slide = vmaddr - seg->vmaddr;
} }
Expand All @@ -334,7 +334,7 @@ class MachOLoader {
} }


if (vmsize != filesize) { if (vmsize != filesize) {
assert(vmsize > filesize); CHECK(vmsize > filesize);
LOG << "mmap(anon) " << mach.filename() << ' ' << name LOG << "mmap(anon) " << mach.filename() << ' ' << name
<< ": " << (void*)(vmaddr + filesize) << "-" << ": " << (void*)(vmaddr + filesize) << "-"
<< (void*)(vmaddr + vmsize) << (void*)(vmaddr + vmsize)
Expand Down Expand Up @@ -553,7 +553,7 @@ class MachOLoader {


LOG << "booting from " << (void*)mach.entry() << "..." << endl; LOG << "booting from " << (void*)mach.entry() << "..." << endl;
fflush(stdout); fflush(stdout);
assert(argc > 0); CHECK(argc > 0);
boot(mach.entry(), argc, argv, envp); boot(mach.entry(), argc, argv, envp);
/* /*
int (*fp)(int, char**, char**) = int (*fp)(int, char**, char**) =
Expand Down
9 changes: 9 additions & 0 deletions log.h
Expand Up @@ -28,6 +28,8 @@
#ifndef LOG_H_ #ifndef LOG_H_
#define LOG_H_ #define LOG_H_


#include <assert.h>

#include "env_flags.h" #include "env_flags.h"


DECLARE_bool(LOG); DECLARE_bool(LOG);
Expand All @@ -42,4 +44,11 @@ DECLARE_bool(LOG);


#define ERR cerr #define ERR cerr


#ifdef NDEBUG
// Do an extra check to avoid warning around unused local variables.
# define CHECK(r) do { if (!(r)) assert(r); } while (0)
#else
# define CHECK(r) assert(r);
#endif

#endif #endif
15 changes: 10 additions & 5 deletions mach-o.cc
Expand Up @@ -25,7 +25,6 @@
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE. // SUCH DAMAGE.


#include <assert.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <inttypes.h> #include <inttypes.h>
Expand All @@ -42,7 +41,13 @@
#include "mach-o.h" #include "mach-o.h"
#include "mach-o/loader.h" #include "mach-o/loader.h"


DEFINE_bool(READ_SYMTAB, true, "Read symtab for better backtrace"); DEFINE_bool(READ_SYMTAB,
#ifdef NDEBUG
false,
#else
true,
#endif
"Read symtab for better backtrace");
DEFINE_bool(READ_DYSYMTAB, false, "Read dysymtab"); DEFINE_bool(READ_DYSYMTAB, false, "Read dysymtab");


typedef long long ll; typedef long long ll;
Expand Down Expand Up @@ -346,7 +351,7 @@ void MachO::readExport(const uint8_t* start,


exports_.push_back(exp); exports_.push_back(exp);


assert(expected_term_end == p); CHECK(expected_term_end == p);
} }


const uint8_t num_children = *p++; const uint8_t num_children = *p++;
Expand All @@ -358,7 +363,7 @@ void MachO::readExport(const uint8_t* start,
p++; p++;


uint64_t off = uleb128(p); uint64_t off = uleb128(p);
assert(off != 0); CHECK(off != 0);
readExport(start, start + off, end, name_buf); readExport(start, start + off, end, name_buf);


name_buf->resize(orig_name_size); name_buf->resize(orig_name_size);
Expand All @@ -383,7 +388,7 @@ MachO::MachO(const char* filename, int fd, size_t offset, size_t len,
} }


void MachO::init(int fd, size_t offset, size_t len) { void MachO::init(int fd, size_t offset, size_t len) {
assert(fd); CHECK(fd);
fd_ = fd; fd_ = fd;
offset_ = offset; offset_ = offset;
if (!len) { if (!len) {
Expand Down

0 comments on commit 2aaf6b3

Please sign in to comment.