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

Fix for link error - undefined CFMutableAttributedStringGetTypeID #357

Conversation

vbadanov
Copy link
Contributor

Intention

Fix for rust-lang/rust#63047 and intellij-rust/intellij-rust#4605

How to reproduce

The following program fails to compile:

use core_foundation::attributed_string::{CFAttributedString, CFMutableAttributedString};
use core_foundation::base::TCFType;

fn main() {
    dbg!(<CFAttributedString as TCFType>::type_id());
    dbg!(<CFMutableAttributedString as TCFType>::type_id());
}
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-m64" "-L" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.198s3ihm7i58x886.rcgu.o" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.29tmhebao6ewa0ll.rcgu.o" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.2d9bu5z2mybg821y.rcgu.o" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.47seajd45h5x4xvx.rcgu.o" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.4m5r63z1bomeava7.rcgu.o" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.dyb0rm2k46lhkz1.rcgu.o" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.ux6g43y1awzd3xm.rcgu.o" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.ysgemo5b5rzmi6m.rcgu.o" "-o" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/foo-cef9f22f855ec251.25q0sul7ku3gti43.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps" "-L" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/libcore_foundation-3b681be94f15488f.rlib" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/liblibc-e84db2977ac0591b.rlib" "/Users/vbadanov/projects/tests/codecoverage-issue-testproject/target/debug/deps/libcore_foundation_sys-2e4eeadb22527df2.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-c9ffd87d7c2bccdf.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-b6d1e628327abbae.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-760b1a8bb4bcc351.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-1660704e36532385.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libbacktrace-c11c21cbed796daf.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libbacktrace_sys-6c38e3c045a3a71f.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-5bfb7cde712ed2a9.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-4540ebf06eb7e37e.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-0a35227c3d306cf2.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-c976a950e872076f.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-ef822b0e650993e5.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-172ea43efe468d24.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-4d87cbd247e9505f.rlib" "/Users/vbadanov/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-3943751ba8f04dce.rlib" "-framework" "CoreFoundation" "-lSystem" "-lresolv" "-lc" "-lm"
  = note: Undefined symbols for architecture x86_64:
            "_CFMutableAttributedStringGetTypeID", referenced from:
                _$LT$core_foundation..attributed_string..CFMutableAttributedString$u20$as$u20$core_foundation..base..TCFType$GT$::type_id::h9f6f71bdd347aca0 in foo-cef9f22f855ec251.198s3ihm7i58x886.rcgu.o
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
          

error: aborting due to previous error

Root cause

Core Foundation framework does not have CFMutableAttributedStringGetTypeID() function.

  1. Documentation of CFMutableAttributedString does not have function CFMutableAttributedStringGetTypeID() listed.
  2. Documentation of CFAttributedString says that there is function CFAttributedStringGetTypeID() available (without word "Mutable").
  3. Documentation of CFAttributedStringGetTypeID() says the following:

    CFMutableAttributedString objects have the same type identifier as CFAttributedString objects.

  4. As a double check - there is no CFMutableAttributedStringGetTypeID() function in C/C++ headers on MacOS, but CFAttributedStringGetTypeID() is available. C/C++ test program (similar to Rust above) does not compile as well.

So, CFAttributedStringGetTypeID() must be used instead of CFMutableAttributedStringGetTypeID()

Solution

  1. In core-foundation-sys: Remove extern CFMutableAttributedStringGetTypeID()
  2. In core-foundation:
    • Replace CFMutableAttributedStringGetTypeID with CFAttributedStringGetTypeID
    • Add test (compilation fails before the fix and is OK after the fix)

@jdm
Copy link
Member

jdm commented Feb 21, 2020

@bors-servo r+
Thanks for fixing this!

@bors-servo
Copy link
Contributor

📌 Commit aa6d1cd has been approved by jdm

@bors-servo
Copy link
Contributor

⌛ Testing commit aa6d1cd with merge 6c77b5a...

@bors-servo
Copy link
Contributor

☀️ Test successful - checks-travis
Approved by: jdm
Pushing 6c77b5a to master...

@bors-servo bors-servo merged commit 6c77b5a into servo:master Feb 21, 2020
bors-servo added a commit to servo/rust-harfbuzz that referenced this pull request Apr 27, 2020
Upgrade core libs

This allows coverage using lcov and grcov. Related to this issue servo/core-foundation-rs#357
nearprotocol-bulldozer bot pushed a commit to near/nearcore that referenced this pull request Jun 10, 2020
test: Fuzz testing RPC #2422 

Fuzzer to test RPC connections, by sending:

- [x] Invalid methods
- [ ] Correct method with invalid formatted data
- [x] Correct method with validly formatted random data

How to run fuzzing
-------------------

```bach
$ cd chain/jsonrpc
$ cargo install cargo-fuzz  # (if not installed)
$ cargo fuzz run fuzz_target_1
```

**Note** there is some bug in Rust, already fixed but still not included in nightly release, somehow related to MacOS Catalina, so fuzzing is possible only in Linux (definitely) and probably on Windows (haven't check). 

References:
rust-lang/rust#63047 (comment)
servo/core-foundation-rs#357

Test plan
---------

1. test query methods with valid random data and ensure RPC response status is 200 and response contains `error` key instead of `result`.
2. test for valid methods with invalid format of data. Should return 200 and `error` in response.
3. test for invalid methods
bors-servo added a commit that referenced this pull request Jun 28, 2020
Bump core-foundation(-sys) to 0.7.1 for release.

Hi! I'm hoping to be able to pull #357 from crates.io and based on other issue threads here it seems that a PR with version bumps is the way to request a release.

I haven't used my local mac recently so I'm relying on CI for now, although if needed I can spin that up and test it locally. LMK?

I'm not actually sure whether the changes to core-foundation since 2019/11 qualify for a patch version bump or a minor one. Thoughts?
catap added a commit to catap/rust-legacy-bootstrap that referenced this pull request Feb 6, 2022
This workaround linker error on attempting to find symbol
CFMutableAttributedStringGetTypeID on macOS.

See details at servo/core-foundation-rs#357
catap added a commit to catap/rust-legacy-bootstrap that referenced this pull request Feb 6, 2022
This workaround linker error on attempting to find symbol
CFMutableAttributedStringGetTypeID on macOS.

See details at servo/core-foundation-rs#357
catap added a commit to catap/rust-legacy-bootstrap that referenced this pull request Feb 6, 2022
This workaround linker error on attempting to find symbol
CFMutableAttributedStringGetTypeID on macOS.

See details at servo/core-foundation-rs#357
catap added a commit to catap/rust-legacy-bootstrap that referenced this pull request Feb 6, 2022
This workaround linker error on attempting to find symbol
CFMutableAttributedStringGetTypeID on macOS.

See details at servo/core-foundation-rs#357
catap added a commit to catap/rust-legacy-bootstrap that referenced this pull request Feb 6, 2022
This workaround linker error on attempting to find symbol
CFMutableAttributedStringGetTypeID on macOS.

See details at servo/core-foundation-rs#357
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

Successfully merging this pull request may close these issues.

None yet

3 participants