summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--DESIGN9
-rw-r--r--Makefile8
2 files changed, 12 insertions, 5 deletions
diff --git a/DESIGN b/DESIGN
index b6e2050..b25b37c 100644
--- a/DESIGN
+++ b/DESIGN
@@ -116,13 +116,20 @@ Build hardening the shipped binary
116---------------------------------- 116----------------------------------
117 117
118The production and debug binaries carry -fstack-protector-strong, PIE and 118The production and debug binaries carry -fstack-protector-strong, PIE and
119_FORTIFY_SOURCE=2; a GNU-style linker also gets full RELRO. Measured cost on 119_FORTIFY_SOURCE=2; every linker but Apple's also gets full RELRO (-z relro,-z now). Measured cost on
120the announce hot path is 300 to 305 nanoseconds, under two per cent, and the 120the announce hot path is 300 to 305 nanoseconds, under two per cent, and the
121individual flags sit inside the run-to-run noise: add_peer has few stack 121individual flags sit inside the run-to-run noise: add_peer has few stack
122buffers, most buffer sizes are known at compile time so FORTIFY emits no 122buffers, most buffer sizes are known at compile time so FORTIFY emits no
123runtime check, and PIE on arm64 is almost free. On x86-64 PIE costs a little 123runtime check, and PIE on arm64 is almost free. On x86-64 PIE costs a little
124more. End to end it is invisible, since a UDP announce is mostly kernel time. 124more. End to end it is invisible, since a UDP announce is mostly kernel time.
125 125
126RELRO is gated on the operating system because Apple's linker rejects -z. The
127branch runs in the shell through a != assignment, the one form both bmake and
128GNU make 4 accept; $(shell) is GNU only and GNU make 3.81, which stock macOS
129ships, has neither. On that old make the != line is inert and leaves RELRO
130empty, which is the right answer for macOS anyway, so every platform resolves
131correctly without a make conditional.
132
126The flags are not in OT_CFLAGS, so the sanitizer test builds do not inherit 133The flags are not in OT_CFLAGS, so the sanitizer test builds do not inherit
127them. AddressSanitizer checks harder than FORTIFY does, and the two clash on 134them. AddressSanitizer checks harder than FORTIFY does, and the two clash on
128FreeBSD, where a FORTIFY plus ASan build aborted a multi hash scrape that the 135FreeBSD, where a FORTIFY plus ASan build aborted a multi hash scrape that the
diff --git a/Makefile b/Makefile
index eed77a0..7ed552c 100644
--- a/Makefile
+++ b/Makefile
@@ -46,9 +46,9 @@ OT_CFLAGS+=-Wall -Wextra -Wwrite-strings -pipe -pthread
46 46
47HARDENING=-fstack-protector-strong -fPIE -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 47HARDENING=-fstack-protector-strong -fPIE -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
48HARDENING_LD=-pie 48HARDENING_LD=-pie
49# Full RELRO is free at runtime and makes the GOT read-only, but Apple's linker 49# Full RELRO on every linker that takes it, which is all but Apple's. See DESIGN.
50# does not accept -z, so enable it for the GNU-style linkers (Linux, the BSDs): 50RELRO_LD!= case `uname -s` in Darwin) ;; *) printf %s -Wl,-z,relro,-z,now ;; esac
51#HARDENING_LD+=-Wl,-z,relro,-z,now 51HARDENING_LD+=$(RELRO_LD)
52OT_LDFLAGS+=-pthread 52OT_LDFLAGS+=-pthread
53 53
54OPTS_debug=-D_DEBUG -g -ggdb 54OPTS_debug=-D_DEBUG -g -ggdb
@@ -78,7 +78,7 @@ $(BINARY).debug: $(SOURCES) $(HEADERS) $(BUILDDEPS)
78 $(CC) -o $@ $(OPTS_debug) $(COMPILE) $(HARDENING) $(SOURCES) $(LINK) $(HARDENING_LD) 78 $(CC) -o $@ $(OPTS_debug) $(COMPILE) $(HARDENING) $(SOURCES) $(LINK) $(HARDENING_LD)
79 79
80$(BUILDSTAMP): FORCE 80$(BUILDSTAMP): FORCE
81 @echo "$(CFLAGS) $(COMPILE) $(LINK)" | cmp -s - $@ 2>/dev/null || echo "$(CFLAGS) $(COMPILE) $(LINK)" > $@ 81 @echo "$(CFLAGS) $(COMPILE) $(HARDENING) $(LINK) $(HARDENING_LD)" | cmp -s - $@ 2>/dev/null || echo "$(CFLAGS) $(COMPILE) $(HARDENING) $(LINK) $(HARDENING_LD)" > $@
82 82
83clean: 83clean:
84 rm -rf $(BINARIES) $(BINARIES:=.dSYM) $(BUILDSTAMP) *.o *~ src/*.o src/*~ 84 rm -rf $(BINARIES) $(BINARIES:=.dSYM) $(BUILDSTAMP) *.o *~ src/*.o src/*~