Provide option to have APE not modify itself

This change introduces ape-no-modify-self.o to the amalgamated release
binaries, which may be used as an alternative to ape.o to make it easier
to use APE in cases where the self-modifying behavior isn't acceptable.

Please note that this alternative copying behavior isn't necessarily
better. It introduces a whole bunch of questions of its own, which are
documented in the ape.S source comment and should be considered by both
the program author as well as the end-user of programs linked this way.

For example, build environments that use read-only file systems and
would prefer to not have a launcher wrapper (like we use in our build)
can use ape-no-modify-self.o instead of ape.o and then set the $TMPDIR
environment variable to point to a sane read-write-exec location.

Fixes #146
See #82
This commit is contained in:
Justine Tunney 2021-04-07 21:01:57 -07:00
parent 59575f7e80
commit da8a08fd58
3 changed files with 77 additions and 6 deletions

View file

@ -6,6 +6,7 @@ o/$(MODE)/test/libc/release/cosmopolitan.zip: \
o/$(MODE)/ape/ape.lds \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape.o \
o/$(MODE)/ape/ape-no-modify-self.o \
o/$(MODE)/cosmopolitan.a
@$(COMPILE) -AZIP -T$@ zip -j $@ $^
@ -37,6 +38,30 @@ o/$(MODE)/test/libc/release/smoke.com.dbg: \
o/$(MODE)/ape/ape.o \
o/$(MODE)/cosmopolitan.a
o/$(MODE)/test/libc/release/smoke-nms.com.dbg: \
test/libc/release/smoke.c \
o/cosmopolitan.h \
o/$(MODE)/ape/ape.lds \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape-no-modify-self.o \
o/$(MODE)/cosmopolitan.a
@$(COMPILE) -ACC $(CC) \
-o $@ \
-Os \
-static \
-no-pie \
-fno-pie \
-nostdlib \
-nostdinc \
-mno-red-zone \
-fno-omit-frame-pointer \
-Wl,-T,o/$(MODE)/ape/ape.lds \
-include o/cosmopolitan.h \
test/libc/release/smoke.c \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/ape/ape-no-modify-self.o \
o/$(MODE)/cosmopolitan.a
o/$(MODE)/test/libc/release/smokecxx.com: \
o/$(MODE)/test/libc/release/smokecxx.com.dbg
@$(COMPILE) -AOBJCOPY -T$< $(OBJCOPY) -S -O binary $< $@
@ -116,6 +141,8 @@ o/$(MODE)/test/libc/release/emulate.ok: \
o/$(MODE)/test/libc/release: \
o/$(MODE)/test/libc/release/smoke.com \
o/$(MODE)/test/libc/release/smoke.com.runs \
o/$(MODE)/test/libc/release/smoke-nms.com \
o/$(MODE)/test/libc/release/smoke-nms.com.runs \
o/$(MODE)/test/libc/release/smokecxx.com \
o/$(MODE)/test/libc/release/smokecxx.com.runs \
o/$(MODE)/test/libc/release/smokeansi.com \