rust-lang / rust-lang/rust

OSX CFI produces relocation issues

Open
#122,848 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-control-flow-integrity A-sanitizers C-bug O-macos PG-exploit-mitigations T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

As seen when testing #122456

I tried this code:

pub fn main() {
  let f: &fn() = &((|| ()) as _);
  f();
} 

compiled with rustc --crate-type=bin -C prefer-dynamic=off -Clto -Zsanitizer=cfi -C target-feature=-crt-static -C codegen-units=1 -C opt-level=0 on OSX

I expected to see this happen: Builds successfully

Instead, this happened: Relocation issues:

command: RUSTC_ICE="0" "/Users/runner/work/rust/rust/build/x86_64-apple-darwin/stage2/bin/rustc" "/Users/runner/work/rust/rust/tests/ui/sanitizer/cfi-closure-fn-ptr-cast.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/Users/runner/.cargo" "--sysroot" "/Users/runner/work/rust/rust/build/x86_64-apple-darwin/stage2" "--target=x86_64-apple-darwin" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "-o" "/Users/runner/work/rust/rust/build/x86_64-apple-darwin/test/ui/sanitizer/cfi-closure-fn-ptr-cast/a" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/Users/runner/work/rust/rust/build/x86_64-apple-darwin/native/rust-test-helpers" "-L" "/Users/runner/work/rust/rust/build/x86_64-apple-darwin/test/ui/sanitizer/cfi-closure-fn-ptr-cast/auxiliary" "--crate-type=bin" "-Cprefer-dynamic=off" "-Clto" "-Zsanitizer=cfi" "-C" "target-feature=-crt-static" "-C" "codegen-units=1" "-C" "opt-level=0"
--- stderr -------------------------------
error: unsupported symbol modifier in branch relocation
   |
note: instantiated into assembly here
note: instantiated into assembly here
  --> <inline asm>:1:2
   |
LL |     jmp __ZN4core3ops8function6FnOnce9call_once17hbd679098001308bdE.cfi@plt

error: unsupported symbol modifier in branch relocation
   |
note: instantiated into assembly here
note: instantiated into assembly here
  --> <inline asm>:5:1
   |
LL | jmp __ZN23cfi_closure_fn_ptr_cast4main17hec6d7c750d93313aE.cfi@plt

error: aborting due to 2 previous errors
------------------------------------------

The patch being tested only adjusts labels, so this bug is about fixing actually producing CFI executables on OSX - all the previously existing tests were codegen only.

It is likely that a much smaller program (possibly anything with an indirect call? any function?) will trigger this issue without needing the FnPtrShim, but I don't personally have a mac to test with.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tests/ui/sanitizer/cfi-closure-fn-ptr-cast.rs and the supplied rustc command on x86_64-apple-darwin, then trace how CFI branch relocations emit the @plt assembly shown in the error. Done means the reproducer builds successfully and the corresponding UI test passes on macOS.

Written by the indexing model from the issue text.

Assessment

Tech stack
macos, rust
Domain
compilers, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.