Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a make target to create a release binary

  • Loading branch information...
commit 2aaf6b30145f4cfed163fa6cba7bb21ebadfa14d 1 parent e1e81de
@shinh authored
Showing with 32 additions and 15 deletions.
  1. +9 −6 Makefile
  2. +4 −4 ld-mac.cc
  3. +9 −0 log.h
  4. +10 −5 mach-o.cc
View
15 Makefile
@@ -1,5 +1,5 @@
-PROFILE_FLAGS=
-GCCFLAGS=-g -Iinclude -Wall -MMD -fno-omit-frame-pointer -O $(PROFILE_FLAGS)
+GCC_EXTRA_FLAGS=
+GCCFLAGS=-g -Iinclude -Wall -MMD -fno-omit-frame-pointer -O $(GCC_EXTRA_FLAGS)
CXXFLAGS=$(GCCFLAGS) -W -Werror
CFLAGS=$(GCCFLAGS) -fPIC
@@ -31,7 +31,10 @@ endif
all: $(EXES)
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)
@@ -52,13 +55,13 @@ $(MACTXTS): %.txt: %.bin
# touch $@
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
- $(CXX) $^ -o $@ -g $(PROFILE_FLAGS)
+ $(CXX) $^ -o $@ -g $(GCC_EXTRA_FLAGS)
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?
libmac/libmac.so: libmac/mac.o
View
8 ld-mac.cc
@@ -90,7 +90,7 @@ class FileMap {
void addWatchDog(uintptr_t addr) {
bool r = maps_.insert(make_pair(addr, (SymbolMap*)NULL)).second;
- assert(r);
+ CHECK(r);
}
const char* dumpSymbol(void* p) {
@@ -316,7 +316,7 @@ class MachOLoader {
LOG << "will rebase: filename=" << mach.filename()
<< ", vmaddr=" << (void*)vmaddr
<< ", last_addr=" << (void*)last_addr_ << endl;
- assert(i == 0);
+ CHECK(i == 0);
vmaddr = last_addr_;
*slide = vmaddr - seg->vmaddr;
}
@@ -334,7 +334,7 @@ class MachOLoader {
}
if (vmsize != filesize) {
- assert(vmsize > filesize);
+ CHECK(vmsize > filesize);
LOG << "mmap(anon) " << mach.filename() << ' ' << name
<< ": " << (void*)(vmaddr + filesize) << "-"
<< (void*)(vmaddr + vmsize)
@@ -553,7 +553,7 @@ class MachOLoader {
LOG << "booting from " << (void*)mach.entry() << "..." << endl;
fflush(stdout);
- assert(argc > 0);
+ CHECK(argc > 0);
boot(mach.entry(), argc, argv, envp);
/*
int (*fp)(int, char**, char**) =
View
9 log.h
@@ -28,6 +28,8 @@
#ifndef LOG_H_
#define LOG_H_
+#include <assert.h>
+
#include "env_flags.h"
DECLARE_bool(LOG);
@@ -42,4 +44,11 @@ DECLARE_bool(LOG);
#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
View
15 mach-o.cc
@@ -25,7 +25,6 @@
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.
-#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
@@ -42,7 +41,13 @@
#include "mach-o.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");
typedef long long ll;
@@ -346,7 +351,7 @@ void MachO::readExport(const uint8_t* start,
exports_.push_back(exp);
- assert(expected_term_end == p);
+ CHECK(expected_term_end == p);
}
const uint8_t num_children = *p++;
@@ -358,7 +363,7 @@ void MachO::readExport(const uint8_t* start,
p++;
uint64_t off = uleb128(p);
- assert(off != 0);
+ CHECK(off != 0);
readExport(start, start + off, end, name_buf);
name_buf->resize(orig_name_size);
@@ -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) {
- assert(fd);
+ CHECK(fd);
fd_ = fd;
offset_ = offset;
if (!len) {
Please sign in to comment.
Something went wrong with that request. Please try again.