diff --git a/makefile b/makefile
index 42b29c807e..157cc9bb9c 100644
--- a/makefile
+++ b/makefile
@@ -94,6 +94,9 @@ endif
ifeq ($(platform),darwin)
build-cflags = $(common-cflags) -fPIC -fvisibility=hidden -I$(src)
lflags = $(common-lflags) -ldl -framework CoreFoundation
+ ifeq ($(bootimage),true)
+ bootimage-lflags = -Wl,-segprot,__BOOT,rwx,rwx
+ endif
rdynamic =
strip-all = -S -x
binaryToMacho = $(native-build)/binaryToMacho
@@ -401,7 +404,7 @@ $(binaryToMacho): $(src)/binaryToMacho.cpp
$(classpath-object): $(build)/classpath.jar $(binaryToMacho)
@echo "creating $(@)"
ifeq ($(platform),darwin)
- $(binaryToMacho) $(build)/classpath.jar \
+ $(binaryToMacho) $(build)/classpath.jar __TEXT __text \
__binary_classpath_jar_start __binary_classpath_jar_end > $(@)
else
(wd=$$(pwd); \
@@ -431,7 +434,7 @@ $(bootimage-bin): $(bootimage-generator)
$(bootimage-object): $(bootimage-bin)
@echo "creating $(@)"
ifeq ($(platform),darwin)
- $(binaryToMacho) $(<) \
+ $(binaryToMacho) $(<) __BOOT __boot \
__binary_bootimage_bin_start __binary_bootimage_bin_end > $(@)
else
(wd=$$(pwd); \
@@ -451,7 +454,7 @@ ifeq ($(platform),windows)
$(dlltool) -d $(@).def -e $(@).exp
$(cc) $(@).exp $(^) $(lflags) -o $(@)
else
- $(cc) $(^) $(rdynamic) $(lflags) -o $(@)
+ $(cc) $(^) $(rdynamic) $(lflags) $(bootimage-lflags) -o $(@)
endif
$(strip) $(strip-all) $(@)
@@ -480,7 +483,7 @@ $(dynamic-library): \
$(vm-objects) $(dynamic-object) $(jni-objects) $(vm-heapwalk-objects) \
$(boot-object) $(vm-classpath-object)
@echo "linking $(@)"
- $(cc) $(^) $(shared) $(lflags) -o $(@)
+ $(cc) $(^) $(shared) $(lflags) $(bootimage-lflags) -o $(@)
$(strip) $(strip-all) $(@)
$(executable-dynamic): $(driver-dynamic-object) $(dynamic-library)
diff --git a/src/binaryToMacho.cpp b/src/binaryToMacho.cpp
index 013b9bfc7f..88259b81cb 100644
--- a/src/binaryToMacho.cpp
+++ b/src/binaryToMacho.cpp
@@ -30,6 +30,7 @@ pad(unsigned n)
void
writeObject(FILE* out, const uint8_t* data, unsigned size,
+ const char* segmentName, const char* sectionName,
const char* startName, const char* endName)
{
unsigned startNameLength = strlen(startName) + 1;
@@ -39,7 +40,7 @@ writeObject(FILE* out, const uint8_t* data, unsigned size,
MH_MAGIC, // magic
CPU_TYPE_I386, // cputype
CPU_SUBTYPE_I386_ALL, // cpusubtype
- MH_OBJECT, // filetype,
+ MH_OBJECT, // filetype
2, // ncmds
sizeof(segment_command)
+ sizeof(section)
@@ -50,7 +51,7 @@ writeObject(FILE* out, const uint8_t* data, unsigned size,
segment_command segment = {
LC_SEGMENT, // cmd
sizeof(segment_command) + sizeof(section), // cmdsize
- "__TEXT", // segname
+ "", // segname
0, // vmaddr
pad(size), // vmsize
sizeof(mach_header)
@@ -64,9 +65,11 @@ writeObject(FILE* out, const uint8_t* data, unsigned size,
0 // flags
};
+ strncpy(segment.segname, segmentName, sizeof(segment.segname));
+
section sect = {
- "__const", // sectname
- "__TEXT", // segname
+ "", // sectname
+ "", // segname
0, // addr
pad(size), // size
sizeof(mach_header)
@@ -81,6 +84,9 @@ writeObject(FILE* out, const uint8_t* data, unsigned size,
0, // reserved2
};
+ strncpy(sect.segname, segmentName, sizeof(sect.segname));
+ strncpy(sect.sectname, sectionName, sizeof(sect.sectname));
+
symtab_command symbolTable = {
LC_SYMTAB, // cmd
sizeof(symtab_command), // cmdsize
@@ -136,9 +142,10 @@ writeObject(FILE* out, const uint8_t* data, unsigned size,
int
main(int argc, const char** argv)
{
- if (argc != 4) {
+ if (argc != 6) {
fprintf(stderr,
- "usage: %s \n",
+ "usage: %s "
+ " \n",
argv[0]);
return -1;
}
@@ -158,7 +165,7 @@ main(int argc, const char** argv)
}
if (data) {
- writeObject(stdout, data, size, argv[2], argv[3]);
+ writeObject(stdout, data, size, argv[2], argv[3], argv[4], argv[5]);
munmap(data, size);
return 0;
} else {