diff --git a/README.md b/README.md index e323d08..39453e2 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,8 @@ build links matters** — a project that also produces shared objects cannot sim | Project | Where `-pie` goes | Why | |---|---|---| | Node.js | `LDFLAGS` | A default Node build links executables only | -| Redis, Bun | `LDFLAGS` | Dependencies are static archives | +| Bun | `LDFLAGS` | Dependencies are static archives | +| Redis | `REDIS_LDFLAGS` | `LDFLAGS` is reused when linking Redis's test modules | | CPython | `LINKFORSHARED` | `LDFLAGS` is reused for stdlib extension `.so` files | | PHP | `EXTRA_LDFLAGS_PROGRAM` | PHP's own program-only link variable | | PostgreSQL | `LDFLAGS_EX` | Postgres separates `_EX` (executables) from `_SL` (shared libs) | diff --git a/recipes/dragonfly.pkl b/recipes/dragonfly.pkl index 714bc46..453174c 100644 --- a/recipes/dragonfly.pkl +++ b/recipes/dragonfly.pkl @@ -20,7 +20,10 @@ version { env = new { [#"CFLAGS"#] = #"-fPIC -fstack-protector-strong"# [#"CXXFLAGS"#] = #"-fPIC -fstack-protector-strong"# - [#"LDFLAGS"#] = #"-pie -Wl,-z,relro -Wl,-z,now"# + // -pie is passed through CMAKE_EXE_LINKER_FLAGS at configure time instead of + // LDFLAGS: CMake seeds CMAKE_SHARED_LINKER_FLAGS from LDFLAGS too, so -pie + // here would break any shared object the build produces. + [#"LDFLAGS"#] = #"-Wl,-z,relro -Wl,-z,now"# } dependencies = new { diff --git a/recipes/redis.pkl b/recipes/redis.pkl index 391feda..1f2997e 100644 --- a/recipes/redis.pkl +++ b/recipes/redis.pkl @@ -18,8 +18,15 @@ version { } env = new { + // Redis builds shared objects as well as executables: its test modules link + // with `$(SHOBJ_LDFLAGS) $(LDFLAGS)`, so -pie in LDFLAGS produces + // `gcc -shared -pie` and the link dies on an undefined reference to `main`. + // + // src/Makefile composes FINAL_LDFLAGS = $(LDFLAGS) $(OPT) $(REDIS_LDFLAGS) + // and uses it only for the executables, so REDIS_LDFLAGS is where -pie goes. [#"CFLAGS"#] = #"-fPIC -fstack-protector-strong"# - [#"LDFLAGS"#] = #"-pie -Wl,-z,relro -Wl,-z,now"# + [#"LDFLAGS"#] = #"-Wl,-z,relro -Wl,-z,now"# + [#"REDIS_LDFLAGS"#] = #"-pie"# } dependencies = new {