Linux executable lazy loading

I am attempting to build a Rust binary that dynamically links to old C libraries. A simple Rust test program is failing to run due to undefined symbol errors even though the LD_LIBRARY_PATH is setup correctly. I also created a simple C application that dynamically links against the libraries and it runs correctly. I have examined the elf headers and I think the difference is that the Rust executable is being built with the -z lazy while the Rust program is being built with -z now. I have tried placing the following section in my .cargo/config but the Rust program still has the NOW flag set. How can I get the Rust program to be linked like the C program? I am attaching reference information below.

[build]
rustflags = [
"-C", "link-arg=-Wl,-z=lazy",
"-C", "relocation-model=dynamic-no-pic"
]

C program elf header information

 0x000000000000000c (INIT)               0x402308
 0x000000000000000d (FINI)               0x4053d4
 0x0000000000000004 (HASH)               0x400290
 0x0000000000000005 (STRTAB)             0x400d10
 0x0000000000000006 (SYMTAB)             0x400500
 0x000000000000000a (STRSZ)              3630 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000015 (DEBUG)              0x0
 0x0000000000000003 (PLTGOT)             0x507c08
 0x0000000000000002 (PLTRELSZ)           1464 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x401d50
 0x0000000000000007 (RELA)               0x401c60
 0x0000000000000008 (RELASZ)             240 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000006ffffffe (VERNEED)            0x401bf0
 0x000000006fffffff (VERNEEDNUM)         3
 0x000000006ffffff0 (VERSYM)             0x401b3e
 0x0000000000000000 (NULL)               0x0

Rust program elf header info:

 0x000000000000000c (INIT)               0x4046b8
 0x000000000000000d (FINI)               0x425e84
 0x0000000000000019 (INIT_ARRAY)         0x62ff60
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x62ff68
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x4002d0
 0x0000000000000005 (STRTAB)             0x401658
 0x0000000000000006 (SYMTAB)             0x4005a8
 0x000000000000000a (STRSZ)              7419 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000015 (DEBUG)              0x0
 0x0000000000000003 (PLTGOT)             0x631a20
 0x0000000000000002 (PLTRELSZ)           552 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x404490
 0x0000000000000007 (RELA)               0x4035d8
 0x0000000000000008 (RELASZ)             3768 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x0000000000000018 (BIND_NOW)
 0x000000006ffffffb (FLAGS_1)            Flags: NOW
 0x000000006ffffffe (VERNEED)            0x4034b8
 0x000000006fffffff (VERNEEDNUM)         6
 0x000000006ffffff0 (VERSYM)             0x403354
 0x0000000000000000 (NULL)               0x0

Information on ld liker options - search for -z ld(1): GNU linker - Linux man page

Cargo build command:
rustc --edition=2018 --crate-name xxxx src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=116469bcb989e727 -C extra-filename=-116469bcb989e727 --out-dir XXX/target/debug/deps -C incremental=XXX/target/debug/incremental -L dependency=XXX/target/debug/deps -C link-arg=-Wl,-z=lazy -C relocation-model=dynamic-no-pic -L native=XXX -L native=/usr/lib/x86_64-linux-gnu -l XXX -l XXX

I believe -z,lazy is incompatible with RELRO as RELRO makes the datastructure that is normally changed at runtime to lazily resolve symbols immutable, forcing all symbols to be resolved at program startup. RELRL is enabled by default on linux: rust/linux_base.rs at ca8078d7b2e40c24a39e5fe2a910afef4c91ebfc · rust-lang/rust · GitHub and I believe can only be disabled using the unstable -Zrelro-level=off.

I am using Rust stable. Is there anyway with Rust stable to have the binary linked link the C binary? Should I submit a Rust issue on this?
I do not have control over the C libraries I am linking against. They are C libraries provided by a vendor that were originally compiled on RHEL 6.4.

You could try defining the missing symbols yourself in the rust code and call std::process::abort().

Unfortunately the vendor libraries I am linking to are a part of a very large vendor application that exposes both a c and a c++ api. The symbols failing to resolve in the rust version are c++ symbols and I think there are hundreds of them, far too many to define. However, they don’t cause an issue at runtime for the C executable because I am only using the c api surface layer.

Can you write a script to take the output of nm and generate a parameter-less stub for each function? I don't think you'd have to match the function signatures if the stub is not going to return or even be called..

Possibly yes, but I don't know the list of functions that I would need to generate a stub for vs functions that do not need a stub. When I call into their C APIs, I may only call the function foo and then internally foo may call bar1 and _a_weird_c++_function and I have no way to know that internal call stack. There are about 380 shared library files and the number of symbols is in the tens of thousands at least. I really just need a way to tell the Rust linking process to match the C linker behavior.

What rustc does technically matches what C probably does on distros that have a focus on security. RELRO is an invention from the C/C++ world. That said I thinl -Clink-arg=-Wl,-znorelro can override the -Wl,-zrelro passed by rustc.

2 Likes

Thank you for the suggestion but I tried it and it does not look like it worked because I get the same symbol issue as before and also the ELF information looks unchanged. Detailed information below.

rustc --edition=2018 --crate-name xxxx src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=116469bcb989e727 -C extra-filename=-116469bcb989e727 --out-dir XXX/target/debug/deps -C incremental=XXX/target/debug/incremental -L dependency=XXX/target/debug/deps -C link-arg=-Wl,-znorelro -C relocation-model=dynamic-no-pic -L native=XXX -L native=/usr/lib/x86_64-linux-gnu -l XXX -l XXX

Executable elf information:

 0x000000000000000c (INIT)               0x404680
 0x000000000000000d (FINI)               0x425e44
 0x0000000000000019 (INIT_ARRAY)         0x62fc00
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x62fc08
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x400298
 0x0000000000000005 (STRTAB)             0x401620
 0x0000000000000006 (SYMTAB)             0x400570
 0x000000000000000a (STRSZ)              7419 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000015 (DEBUG)              0x0
 0x0000000000000003 (PLTGOT)             0x631bd0
 0x0000000000000002 (PLTRELSZ)           552 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x404458
 0x0000000000000007 (RELA)               0x4035a0
 0x0000000000000008 (RELASZ)             3768 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x0000000000000018 (BIND_NOW)
 0x000000006ffffffb (FLAGS_1)            Flags: NOW
 0x000000006ffffffe (VERNEED)            0x403480
 0x000000006fffffff (VERNEEDNUM)         6
 0x000000006ffffff0 (VERSYM)             0x40331c
 0x0000000000000000 (NULL)               0x0

Can you touch src/main.rs (to force a rebuild) and then prefix the cargo build with RUSTC_LOG=info? Near the end of the log output the full linker invocation should be shown. Can you post it here?

I ran the command but didn't see any log output? Is there something else I need to do?

-bash-4.2$ RUSTC_LOG=debug cargo build
   Compiling XXX v0.1.0 (XXX)
    Finished dev [unoptimized + debuginfo] target(s) in 0.61s

My apologies, I was trying an older version of Rust which I guess didn't support that variable. Below is the output:

cat .cargo/config
[build]
rustflags = [
"-C", "link-arg=-Wl,--unresolved-symbols=ignore-all",
"-C", "link-arg=-Wl,-znorelro",
"-C", "relocation-model=dynamic-no-pic"
]
INFO rustc_codegen_ssa::back::link preparing Executable to "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91"
INFO rustc_codegen_ssa::back::link "cc" "-m64" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.13p9e1ntyogo9xsq.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.1iij31zcahtqtiv5.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.1l6169r8k8eut7l2.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.2gjar0q85zo53a76.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.2k238mae54tufgj9.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.2khfd30djo2j9kj2.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.30j9pt2j18mofsvb.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.3aliuipsukidwcp1.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.3hccpq6246r15ccj.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.3mblox8452khn7gt.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.3t4cjyhj779kk0qr.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.3zuhas95lhzq610q.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.45wlivfnv8f4n4m0.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.4d3znlnisojq460.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.4kfpl27e23y5yblb.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.4tsmg47mo9ot09rg.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.56udpy3ecn6gwk3v.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.5a3amov6yy7wfscc.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.5cf61klwqdixyzvj.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.5orcigdhwyefptr.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.9x7slzthbld3jn.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.cde9lw0m0vpja0a.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.gzsb73e5bh99x9g.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.lphb1hwcx9397qd.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.q46zvmgwxroxyjw.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.uov2smtu6r3uncy.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.y30a08oijsqtlo9.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.1lyc4h18v76f6y14.rcgu.o" "-Wl,--as-needed" "-L" "CODEROOT/target/debug/deps" "-L" "/LIBROOT" "-L" "/usr/lib/x86_64-linux-gnu" "-L" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lae" "-lbom" "-lepm" "-lfclasses" "-lform" "-ltcinit" "-ltc" "-ltccore" "-lbase_utils" "-lps" "-lpublication" "-lqry" "-lres" "-lsa" "-ltcsoaprojectmanagement" "-lcfilter" "-lstdc++" "-Wl,--start-group" "-Wl,-Bstatic" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-008055cc7d873802.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-06f01ac2578bda94.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-f9a3c3274a1835e0.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-d4cbb754ee9f4daa.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-95c14e1c1e3ebcc4.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-d489f0ca872880cc.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-75f07df0b18fea39.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-0c35b278736219a2.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-e530649c9a06e3c6.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-6b148909d375a785.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-cd15fa647f4775d1.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-74be3a703f788ba2.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-8f2c5b445c28b2e3.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-8480e85e0be96197.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-ac23a75f6f42004e.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-557ba8776e04d182.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-4beb03d03503c439.rlib" "-Wl,--end-group" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-dd7db1bec6909f24.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91" "-Wl,--gc-sections" "-no-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-Wl,--unresolved-symbols=ignore-all" "-Wl,-znorelro"
INFO rustc_codegen_ssa::back::link linker output: "cc: error: unrecognized command line option '-no-pie'\n"
WARN rustc_codegen_ssa::back::link Linker does not support -no-pie command line option. Retrying without.
INFO rustc_codegen_ssa::back::link "cc" "-m64" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.13p9e1ntyogo9xsq.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.1iij31zcahtqtiv5.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.1l6169r8k8eut7l2.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.2gjar0q85zo53a76.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.2k238mae54tufgj9.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.2khfd30djo2j9kj2.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.30j9pt2j18mofsvb.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.3aliuipsukidwcp1.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.3hccpq6246r15ccj.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.3mblox8452khn7gt.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.3t4cjyhj779kk0qr.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.3zuhas95lhzq610q.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.45wlivfnv8f4n4m0.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.4d3znlnisojq460.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.4kfpl27e23y5yblb.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.4tsmg47mo9ot09rg.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.56udpy3ecn6gwk3v.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.5a3amov6yy7wfscc.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.5cf61klwqdixyzvj.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.5orcigdhwyefptr.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.9x7slzthbld3jn.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.cde9lw0m0vpja0a.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.gzsb73e5bh99x9g.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.lphb1hwcx9397qd.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.q46zvmgwxroxyjw.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.uov2smtu6r3uncy.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.y30a08oijsqtlo9.rcgu.o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91.1lyc4h18v76f6y14.rcgu.o" "-Wl,--as-needed" "-L" "CODEROOT/target/debug/deps" "-L" "/LIBROOT" "-L" "/usr/lib/x86_64-linux-gnu" "-L" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lae" "-lbom" "-lepm" "-lfclasses" "-lform" "-ltcinit" "-ltc" "-ltccore" "-lbase_utils" "-lps" "-lpublication" "-lqry" "-lres" "-lsa" "-ltcsoaprojectmanagement" "-lcfilter" "-lstdc++" "-Wl,--start-group" "-Wl,-Bstatic" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-008055cc7d873802.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-06f01ac2578bda94.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-f9a3c3274a1835e0.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-d4cbb754ee9f4daa.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-95c14e1c1e3ebcc4.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-d489f0ca872880cc.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-75f07df0b18fea39.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-0c35b278736219a2.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-e530649c9a06e3c6.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-6b148909d375a785.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-cd15fa647f4775d1.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-74be3a703f788ba2.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-8f2c5b445c28b2e3.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-8480e85e0be96197.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-ac23a75f6f42004e.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-557ba8776e04d182.rlib" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-4beb03d03503c439.rlib" "-Wl,--end-group" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-dd7db1bec6909f24.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "USERROOT/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "CODEROOT/target/debug/deps/appname-3aa5bdb40b601d91" "-Wl,--gc-sections" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-Wl,--unresolved-symbols=ignore-all" "-Wl,-znorelro"

I think you also need the "-C", "link-arg=-Wl,-z=lazy", you initially used in combination with the args you use right now.

I tried it but it didn't work because cargo is adding in a -znow flag earlier in the linker order and it looks like that flag is overriding the -zlazy.

[build]
rustflags = [
"-C", "link-arg=-Wl,--unresolved-symbols=ignore-all",
"-C", "link-arg=-Wl,-znorelro",
"-C", "link-arg=-Wl,-zlazy",
"-C", "relocation-model=dynamic-no-pic"
]
INFO rustc_codegen_ssa::back::link "cc" "-m64" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.13p9e1ntyogo9xsq.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.1iij31zcahtqtiv5.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.1l6169r8k8eut7l2.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.2gjar0q85zo53a76.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.2k238mae54tufgj9.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.2khfd30djo2j9kj2.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.30j9pt2j18mofsvb.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.3aliuipsukidwcp1.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.3hccpq6246r15ccj.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.3mblox8452khn7gt.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.3t4cjyhj779kk0qr.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.3zuhas95lhzq610q.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.45wlivfnv8f4n4m0.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.4d3znlnisojq460.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.4kfpl27e23y5yblb.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.4tsmg47mo9ot09rg.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.56udpy3ecn6gwk3v.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.5a3amov6yy7wfscc.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.5cf61klwqdixyzvj.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.5orcigdhwyefptr.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.9x7slzthbld3jn.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.cde9lw0m0vpja0a.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.gzsb73e5bh99x9g.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.lphb1hwcx9397qd.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.q46zvmgwxroxyjw.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.uov2smtu6r3uncy.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.y30a08oijsqtlo9.rcgu.o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91.1lyc4h18v76f6y14.rcgu.o" "-Wl,--as-needed" "-L" "USERHOME/code/teamcenter/APPNAME/target/debug/deps" "-L" "/LIBDIR" "-L" "/usr/lib/x86_64-linux-gnu" "-L" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lae" "-lbom" "-lepm" "-lfclasses" "-lform" "-ltcinit" "-ltc" "-ltccore" "-lbase_utils" "-lps" "-lpublication" "-lqry" "-lres" "-lsa" "-ltcsoaprojectmanagement" "-lcfilter" "-lstdc++" "-Wl,--start-group" "-Wl,-Bstatic" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-008055cc7d873802.rlib" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-06f01ac2578bda94.rlib" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-f9a3c3274a1835e0.rlib" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-d4cbb754ee9f4daa.rlib" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-95c14e1c1e3ebcc4.rlib" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-d489f0ca872880cc.rlib" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-75f07df0b18fea39.rlib" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-0c35b278736219a2.rlib" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-e530649c9a06e3c6.rlib" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-6b148909d375a785.rlib" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-cd15fa647f4775d1.rlib" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-74be3a703f788ba2.rlib" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-8f2c5b445c28b2e3.rlib" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-8480e85e0be96197.rlib" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-ac23a75f6f42004e.rlib" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-557ba8776e04d182.rlib" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-4beb03d03503c439.rlib" "-Wl,--end-group" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-dd7db1bec6909f24.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "USERHOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "USERHOME/code/teamcenter/APPNAME/target/debug/deps/APPNAME-3aa5bdb40b601d91" "-Wl,--gc-sections" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-Wl,--unresolved-symbols=ignore-all" "-Wl,-znorelro" "-Wl,-zlazy"

Doesn't seem like it is possible to avoid -znow without disabling relro in rustc: rust/linker.rs at 3013b26947e956352f95edfa39251319520cb06c · rust-lang/rust · GitHub

What kind of project are you working on? Would it be acceptable to use nightly or is it stability very important. Nightly releases will still pass the full rustc test suite as the @bors bot won't merge any PR until CI passes, so it is not like nightly will be very buggy. You may get hit by a regression once in a while, but if you report it, it will most of the time be fixed within a couple of days. If any regressions or bugs are unacceptable for the kind of project you work on, I completely understand that you don't want to use nightly.

Stability is very important to us because there are several thousand unique users who use our tools for multiple hours per day. I also work with a team of about 10 other developers and I think that if we make the jump to nightly, it would be very easy for them to start using other nightly-only features and that is a risk I do not want to take.
I do not understand the decision to force table full relro for all Rust builds when the underlying Linux distributions do not default that in GCC compiles. Even if Rust set relro as the default, I could understand that but I would also like a way - configuration setting, environment variable, etc... so that I could disable that.
At the present state, I can use Rust to link against these vendor libraries on Windows because the vendor supplies libraries for both platforms. On Windows, I am seeing huge (200%) performance improvements from using Rust vs our current Go implementation. I would really like to be able to use Rust on Linux for our production environment. Should I submit a Github issue or how do you recommend moving forward?

This could be somewhat mitigated by passing -Zallow-features= to rustc. This sets an empty whitelist for feature flags you can enable.

Security. Rust enables some hardening options by default.

There is (-Zrelro-level) but like all new compiler options it started out as nightly only. So far nobody has requested stabilization yet AFAIK. In fact I couldn't even find a tracking issue for it, like unstable feature should have.

You could submit an issue to propose stabilization of -Zrelro-level.

4 Likes

I will submit the PR. In the meantime, is there any way to tell the rust build process to invoke a custom linker and via a shell script I could modify the linker options before the real linker is invoked?

Custom linker can be using -Clinker. Didn't think of using a wrapper around the linker to filter -znow.