Skip to content

Commit a4cf55e

Browse files
usamoiKenjiBrown
authored andcommitted
tell C compiler to put code and data in separate sections (pgcentralfoundation#2006)
Fixes a known issue (cshim requires LTO) in pgcentralfoundation#1934.
1 parent 2c228bc commit a4cf55e

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

.cargo/config.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@ r = "run --features"
77
[target.'cfg(target_os="macos")']
88
# Postgres symbols won't be available until runtime
99
rustflags = ["-Clink-arg=-Wl,-undefined,dynamic_lookup"]
10-
11-
[target.'cfg(target_env="msvc")']
12-
linker = "lld-link"
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
[target.'cfg(target_os="macos")']
22
# Postgres symbols won't be available until runtime
33
rustflags = ["-Clink-arg=-Wl,-undefined,dynamic_lookup"]
4-
5-
[target.'cfg(target_env="msvc")']
6-
linker = "lld-link"

pgrx-bindgen/src/build.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,11 +1009,14 @@ fn build_shim(
10091009
std::fs::copy(shim_src, shim_dst).unwrap();
10101010

10111011
let mut build = cc::Build::new();
1012-
if let Some("msvc") = env_tracked("CARGO_CFG_TARGET_ENV").as_deref() {
1013-
// without this, pgrx_embed would be linked to postgres.lib
1014-
build.compiler("clang");
1015-
build.archiver("llvm-lib");
1016-
build.flag("-flto=thin");
1012+
let compiler = build.get_compiler();
1013+
if compiler.is_like_gnu() || compiler.is_like_clang() {
1014+
build.flag("-ffunction-sections");
1015+
build.flag("-fdata-sections");
1016+
}
1017+
if compiler.is_like_msvc() {
1018+
build.flag("/Gy");
1019+
build.flag("/Gw");
10171020
}
10181021
for pg_target_include in pg_target_includes(major_version, pg_config)?.iter() {
10191022
build.flag(&format!("-I{pg_target_include}"));

0 commit comments

Comments
 (0)