Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails on 1.66 nightly (Linux) #1

Open
sempervictus opened this issue Oct 3, 2022 · 13 comments
Open

Build fails on 1.66 nightly (Linux) #1

sempervictus opened this issue Oct 3, 2022 · 13 comments

Comments

@sempervictus
Copy link

Builds in Linux seem to require -Zbuild-std which in turn appears to break the linker script:

[cargo-make] INFO - Running Task: generate-linker-script
[cargo-make] INFO - Execute Command: "cargo" "build" "-p" "rustbof" "--target" "i686-pc-windows-gnu" "--release" "-Zbuild-std"
  Downloaded unicode-width v0.1.10
  Downloaded compiler_builtins v0.1.79
  Downloaded libc v0.2.131
  Downloaded 3 crates (779.4 KB) in 0.30s
   Compiling compiler_builtins v0.1.79
   Compiling core v0.0.0 (/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling libc v0.2.131
   Compiling cc v1.0.73
   Compiling std v0.0.0 (/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std)
   Compiling windows_i686_gnu v0.33.0
   Compiling paste v1.0.9
   Compiling unwind v0.0.0 (/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/unwind)
   Compiling rustc-std-workspace-core v1.99.0 (/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc)
   Compiling cfg-if v0.1.10
   Compiling cfg-if v1.0.0
   Compiling rustc-demangle v0.1.21
   Compiling rustc-std-workspace-alloc v1.99.0 (/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-alloc)
   Compiling panic_abort v0.0.0 (/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_abort)
   Compiling panic_unwind v0.0.0 (/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_unwind)
   Compiling std_detect v0.1.5 (/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/stdarch/crates/std_detect)
   Compiling hashbrown v0.12.3
   Compiling proc_macro v0.0.0 (/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro)
   Compiling windows-sys v0.33.0
   Compiling bofhelper v0.1.0 (/opt/code/CPP/Cobalt/rust_bof/libs/bofhelper)
   Compiling bofalloc v0.1.0 (/opt/code/CPP/Cobalt/rust_bof/libs/bofalloc)
   Compiling bofentry v0.1.0 (/opt/code/CPP/Cobalt/rust_bof/libs/bofentry)
   Compiling rustbof v0.1.0 (/opt/code/CPP/Cobalt/rust_bof/rustbof)
    Finished release [optimized] target(s) in 16.62s
[cargo-make] INFO - Running Task: combine-objs
i686-w64-mingw32-ld: target/i686-pc-windows-gnu/release/deps/alloc-c1376b3f5d68bdf1.o:alloc.982fc090-cgu:(.text+0x894): multiple definition of `__rdl_oom'; target/i686-pc-windows-gnu/release/deps/alloc-74afa7004456a0da.o:alloc.0a9fc5a7-cgu:(.text+0x8a3): first defined here
i686-w64-mingw32-ld: target/i686-pc-windows-gnu/release/deps/alloc-c1376b3f5d68bdf1.o:alloc.982fc090-cgu:(.text+0x89b): multiple definition of `__rg_oom'; target/i686-pc-windows-gnu/release/deps/alloc-74afa7004456a0da.o:alloc.0a9fc5a7-cgu:(.text+0x8aa): first defined here
i686-w64-mingw32-ld: target/i686-pc-windows-gnu/release/deps/bofalloc-98ec48f3d7d861fd.o:bofalloc.2293be5f-:(.text+0xa): multiple definition of `__rust_alloc'; target/i686-pc-windows-gnu/release/deps/bofalloc-3814d15b5ff5eacd.o:bofalloc.95ebbabd-:(.text+0x28): first defined here
i686-w64-mingw32-ld: target/i686-pc-windows-gnu/release/deps/bofalloc-98ec48f3d7d861fd.o:bofalloc.2293be5f-:(.text+0x29): multiple definition of `__rust_dealloc'; target/i686-pc-windows-gnu/release/deps/bofalloc-3814d15b5ff5eacd.o:bofalloc.95ebbabd-:(.text+0x47): first defined here
i686-w64-mingw32-ld: target/i686-pc-windows-gnu/release/deps/bofalloc-98ec48f3d7d861fd.o:bofalloc.2293be5f-:(.text+0x48): multiple definition of `__rust_realloc'; target/i686-pc-windows-gnu/release/deps/bofalloc-3814d15b5ff5eacd.o:bofalloc.95ebbabd-:(.text+0x66): first defined here
...
i686-w64-mingw32-ld: target/i686-pc-windows-gnu/release/deps/std-9e8e3aeab9a462de.o:std.f1feb203-cgu.0:(.text+0x1d8eb): multiple definition of `rust_begin_unwind'; target/i686-pc-windows-gnu/release/deps/std-44868e07d57d2f0e.o:std.3d4f0bca-cgu.0:(.text+0x19c31): first defined here
i686-w64-mingw32-ld: target/i686-pc-windows-gnu/release/deps/std-9e8e3aeab9a462de.o:std.f1feb203-cgu.0:(.text+0x1dc87): multiple definition of `rust_panic'; target/i686-pc-windows-gnu/release/deps/std-44868e07d57d2f0e.o:std.3d4f0bca-cgu.0:(.text+0x19fc3): first defined here
[cargo-make] ERROR - Error while executing command, exit code: 1
[cargo-make] WARN - Build Failed.

Build environment is Arch, MinGW 12.2.

@wumb0
Copy link
Owner

wumb0 commented Oct 3, 2022 via email

@wumb0
Copy link
Owner

wumb0 commented Oct 3, 2022 via email

@sempervictus
Copy link
Author

Thanks, and i'm by no means a CS person :). I'm from the MSF world, and we can run beacons in meterpreter now.
Will try that this evening. Thank you

@sempervictus
Copy link
Author

No such luck:

$ cargo +nightly make
[cargo-make] INFO - cargo make 0.36.1
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: default
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: generate-linker-script
[cargo-make] INFO - Execute Command: "cargo" "build" "-p" "rustbof" "--target" "i686-pc-windows-gnu" "--release" "-Zbuild-std=core"
   Compiling windows_i686_gnu v0.33.0
error[E0463]: can't find crate for `std`
  |
  = note: the `i686-pc-windows-gnu` target may not support the standard library
  = note: `std` is required by `windows_i686_gnu` because it does not declare `#![no_std]`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

For more information about this error, try `rustc --explain E0463`.
error: could not compile `windows_i686_gnu` due to previous error
[cargo-make] ERROR - Error while executing command, exit code: 101
[cargo-make] WARN - Build Failed.

same without trying to build it at all:

$ cargo +nightly make
[cargo-make] INFO - cargo make 0.36.1
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: default
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: generate-linker-script
[cargo-make] INFO - Execute Command: "cargo" "build" "-p" "rustbof" "--target" "i686-pc-windows-gnu" "--release"
   Compiling windows_i686_gnu v0.33.0
error[E0463]: can't find crate for `std`
  |
  = note: the `i686-pc-windows-gnu` target may not support the standard library
  = note: `std` is required by `windows_i686_gnu` because it does not declare `#![no_std]`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

For more information about this error, try `rustc --explain E0463`.
error: could not compile `windows_i686_gnu` due to previous error
[cargo-make] ERROR - Error while executing command, exit code: 101
[cargo-make] WARN - Build Failed.

@b1scoito
Copy link
Contributor

b1scoito commented Feb 23, 2023

Build fails from master with the latest nightly toolchains, and even when using rustc version 1.61 installing the nightly-2022-03-01 toolchains which are the latest ones from the last commit. I've spent the past 3-4 hours trying to get this to compile, thinking it might be something I missed (well, probably). But I figured out that when using cargo make it shows that windows-sys (the library used for the windows bindings, doesn't support no_std which is quite confusing since this project uses no_std. When compiled directly using cargo build -Zbuild-std all object files get compiled successfully, however the build tasks in the make file don't get ran (obviously.)

image

In this screenshot, the first try is using cargo make, windows_x86_64_gnu doesn't compile due to the no no_std support. however, on the second try, using directly the cargo command it does successfully compile.

I'm very much confused.

@b1scoito
Copy link
Contributor

b1scoito commented Feb 23, 2023

Ok. Apparently cargo make looks for a Makefile.toml (with an uppercase letter "M") and the file on the directory is makefile.toml so I had to specify the makefile like so: cargo make --makefile makefile.toml, after that, everything compiled. But I got another error, multiple definitions on ld, by adding the argument --allow-multiple-definition to the ld command on the makefile, it won't report those errors as fatal, and will just ignore them. With this, I was able to successfully compile everything.

@b1scoito
Copy link
Contributor

Well, adding --allow-multiple-definition did not seem like the solution (and it seems a pretty bad idea too), COFFLoader doesn't run the generated BOFs, any ideas on what might be happening here?

image

@wumb0
Copy link
Owner

wumb0 commented Feb 23, 2023 via email

@b1scoito
Copy link
Contributor

b1scoito commented Feb 23, 2023

Still gives me the same errors on combine-objs after cargo make --makefile makefile.toml clean and cargo clean.

.o files for stdlib are present because otherwise it wouldn't compile, as windows-sys doesn't support no_std apparently, I had to append -Zbuild-std on the build task for it to compile. That's so weird.

When it's ran on a newly-installed toolchain, it'll show this error:
image

@b1scoito
Copy link
Contributor

b1scoito commented Feb 23, 2023

Ok. I managed to successfully compile everything on latest rust version and latest windows-sys version.

I'm using this Dockerfile for compilation on Windows:

FROM rust:latest

WORKDIR /app

RUN apt update; apt upgrade -y 
RUN apt install -y g++-mingw-w64-x86-64 gcc-mingw-w64-x86-64 g++-mingw-w64-i686 gcc-mingw-w64-i686

RUN rustup toolchain install nightly-x86_64-unknown-linux-gnu
RUN rustup toolchain install nightly-x86_64-pc-windows-gnu
RUN rustup toolchain install nightly-i686-pc-windows-gnu
RUN rustup default nightly

RUN cargo install cargo-make

CMD ["cargo", "make", "--makefile", "makefile.toml"]

Running with: docker run --rm -v ...\dev\rust_bof:/app rust_cross_compile/windowscustom

And added these lines to the makefile.toml:

[tasks.build]
toolchain = "nightly"
install_crate = { rustup_component_name = "rust-src" }

The fix for the no_std build was upgrading the windows-sys version to latest, which apparently supports no_std fully.

Can I PR those changes?

@wumb0
Copy link
Owner

wumb0 commented Feb 24, 2023 via email

@b1scoito
Copy link
Contributor

b1scoito commented Feb 25, 2023

PR Created: #2
I commited the makefile with the uppercase letter M but it doesn't appear to have worked, strange.

@wumb0
Copy link
Owner

wumb0 commented Feb 25, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants