Lakelezz / audiopus_sys

Rust FFI-binding of Opus.
ISC License
14 stars 21 forks source link

Stack smashing protection causing issues with Windows targets #12

Open FrancisRussell opened 1 year ago

FrancisRussell commented 1 year ago

I've been using audiopus_sys 0.2.2 via audiopus 0.3.0-rc.0, In my Cargo.toml, I've used the static option to ensure that libopus is built from source. In an Ubuntu environment I've been cross compiling my project for the x86_64-pc-windows-gnu and i686-pc-windows-gnu targets. However, I have encountered linking issues due to stack-smashing protection (SSP). These manifest as follows:

  = note: /target/i686-pc-windows-gnu/debug/deps/libaudiopus_sys-b661dfe0e9f65081.rlib(opus_decoder.c.obj): In function `opus_decoder_get_size':
          /cargo/registry/src/github.com-1ecc6299db9ec823/audiopus_sys-0.2.2/opus/src/opus_decoder.c:103: undefined reference to `__stack_chk_guard'
          /cargo/registry/src/github.com-1ecc6299db9ec823/audiopus_sys-0.2.2/opus/src/opus_decoder.c:114: undefined reference to `__stack_chk_guard'
          /cargo/registry/src/github.com-1ecc6299db9ec823/audiopus_sys-0.2.2/opus/src/opus_decoder.c:114: undefined reference to `__stack_chk_fail'
          /target/i686-pc-windows-gnu/debug/deps/libaudiopus_sys-b661dfe0e9f65081.rlib(opus_decoder.c.obj): In function `opus_decoder_init':
          /cargo/registry/src/github.com-1ecc6299db9ec823/audiopus_sys-0.2.2/opus/src/opus_decoder.c:117: undefined reference to `__stack_chk_guard'
          /cargo/registry/src/github.com-1ecc6299db9ec823/audiopus_sys-0.2.2/opus/src/opus_decoder.c:157: undefined reference to `__stack_chk_guard'
          /cargo/registry/src/github.com-1ecc6299db9ec823/audiopus_sys-0.2.2/opus/src/opus_decoder.c:157: undefined reference to `__stack_chk_fail'
          /target/i686-pc-windows-gnu/debug/deps/libaudiopus_sys-b661dfe0e9f65081.rlib(opus_decoder.c.obj): In function `opus_decode_frame':
          /cargo/registry/src/github.com-1ecc6299db9ec823/audiopus_sys-0.2.2/opus/src/opus_decoder.c:222: undefined reference to `__stack_chk_guard'
          /cargo/registry/src/github.com-1ecc6299db9ec823/audiopus_sys-0.2.2/opus/src/opus_decoder.c:624: undefined reference to `__stack_chk_guard'
          /cargo/registry/src/github.com-1ecc6299db9ec823/audiopus_sys-0.2.2/opus/src/opus_decoder.c:624: undefined reference to `__stack_chk_fail'

From what I can tell, the Opus library will compile using SSP functionality by default which is what causes these references. I was able to work around the issue by creating a .cargo/config.toml as follows:

[target.x86_64-pc-windows-gnu]
rustflags = [ "-C", "link-arg=-lssp" ]

[target.i686-pc-windows-gnu]
rustflags = [ "-C", "link-arg=-lssp" ]

I also have a build for x86-64 musl, but did not encounter this issue.

WcaleNieWolny commented 1 year ago

I have the same issue

WcaleNieWolny commented 1 year ago

I have a dirty fix on my fork. You can use it by adding this to Cargo.toml

[patch.crates-io]
audiopus_sys = { git = "https://github.com/WcaleNieWolny/audiopus_sys.git", branch = "stable-changes" }