* How to Compile Static Executables w/ PIE + SSP + BIND_NOW?
[not found] <1258963047.1677810.1473392956126.ref@mail.yahoo.com>
@ 2016-09-09 3:49 ` Musl Questions
2016-09-09 22:57 ` Rich Felker
0 siblings, 1 reply; 2+ messages in thread
From: Musl Questions @ 2016-09-09 3:49 UTC (permalink / raw)
To: musl
[-- Attachment #1: Type: text/plain, Size: 676 bytes --]
Arch Linux. Example app: mksh.
CC=musl-gcc
CFLAGS+=' -static'
export CC CFLAGS
sh Build.sh -r -c lto
Using typical build flags:
CFLAGS="-march=amdfam15 -O2 -pipe -fstack-protector-all -fPIE"
LDFLAGS="-Wl,-z,now -Wl,-z,relro"
Does produce a static executable but without PIE or SSP. Have tried various options to no avail:
CFLAGS+=' -static -pie'
..with..
CFLAGS="-O2 -fstack-protector-strong"
LDFLAGS="-Wl,-z,now -Wl,-z,relro"
...and...
CFLAGS+=' -shared -pie -static'
..with..
CFLAGS="-O2 -fstack-protector-all"
LDFLAGS="-Wl,-z,now -Wl,-z,relro"
...and many other combos without success. How to create a static exe built against musl with PIE + SSP + BIND_NOW?
[-- Attachment #2: Type: text/html, Size: 1169 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: How to Compile Static Executables w/ PIE + SSP + BIND_NOW?
2016-09-09 3:49 ` How to Compile Static Executables w/ PIE + SSP + BIND_NOW? Musl Questions
@ 2016-09-09 22:57 ` Rich Felker
0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2016-09-09 22:57 UTC (permalink / raw)
To: Musl Questions; +Cc: musl
On Fri, Sep 09, 2016 at 03:49:16AM +0000, Musl Questions wrote:
> Arch Linux. Example app: mksh.
>
> CC=musl-gcc
> CFLAGS+=' -static'
> export CC CFLAGS
> sh Build.sh -r -c lto
Generally -static belongs in LDFLAGS not CFLAGS, but mksh seems to
have an unusual build process so it's hard to be sure what it expects
without reading the source.
> Using typical build flags:
>
> CFLAGS="-march=amdfam15 -O2 -pipe -fstack-protector-all -fPIE"
> LDFLAGS="-Wl,-z,now -Wl,-z,relro"
>
> Does produce a static executable but without PIE or SSP. Have tried
> various options to no avail:
>
> CFLAGS+=' -static -pie'
>
> ...with..
>
> CFLAGS="-O2 -fstack-protector-strong"
> LDFLAGS="-Wl,-z,now -Wl,-z,relro"
> ....and...
>
> CFLAGS+=' -shared -pie -static'
>
> ...with..
>
> CFLAGS="-O2 -fstack-protector-all"
> LDFLAGS="-Wl,-z,now -Wl,-z,relro"
> ....and many other combos without success. How to create a static
> exe built against musl with PIE + SSP + BIND_NOW?
SSP and the other issues are separate, so let's start with SSP. It
does not need any special link options and should work as long as you
compile with the right flags.
As for static pie, GCC does not support it upstream yet. If you have a
new enough binutils (2.26 or later, I think) it should have the option
which is needed to make static pie work, which is --no-dynamic-linker.
You can try adding to LDFLAGS:
-pie -static-libgcc -Wl,-static -Wl,--no-dynamic-linker
I haven't tested this lately but I think it should work.
Alternatively you could use a dedicated musl-targeting toolchain with
the static pie support patches applied; musl-cross-make can produce
one for you.
Rich
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-09-09 22:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <1258963047.1677810.1473392956126.ref@mail.yahoo.com>
2016-09-09 3:49 ` How to Compile Static Executables w/ PIE + SSP + BIND_NOW? Musl Questions
2016-09-09 22:57 ` Rich Felker
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).