-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
link error with undefined reference to `main' on Arch #23
Comments
Hmm no ideas off the top of my head, I'll look into it. Unless @yodaldevoid has any thoughts |
Solve one linker problem and you become an expert... I kid of course. Of the top of my head I can't think of any reason why this would fail like this. What version of gcc were you using with your Xenial container? |
You raise a linker issue and you solve another, think that makes you the resident expert ;) |
Well, I more or less caused the second, so... |
The container I was using was that succeeded muslrust so I guess |
I don't suppose the project in question is on github or gitlab so I can try it out myself? If that's not possible a minimal project that recreates the same issue that you can share would be helpful. I'm also wondering if it has any relation to rust-lang/rust#41416 |
Bad news is that I can't share it, but good news is that I've identified a crate that causes the failure; serde_derive at 0.9.15 that was in my Cargo.toml. A simple lib.rs with: #[macro_use]
extern crate serde_derive;
#[cfg(test)]
mod tests {
#[test]
fn blah() {
assert_eq!(true, true, "testing");
}
} Will fail in the manner above. I tried updating serde_derive as well, but still no luck. cargo list --tree
└── serde_derive (1.0.11)
├── quote (0.3.15)
├── serde_derive_internals (0.15.1)
│ ├── syn (0.11.11)
│ │ ├── quote (0.3.15)
│ │ ├── synom (0.11.3)
│ │ │ └── unicode-xid (0.0.4)
│ │ └── unicode-xid (0.0.4)
│ └── synom (0.11.3)
│ └── unicode-xid (0.0.4)
└── syn (0.11.11)
├── quote (0.3.15)
├── synom (0.11.3)
│ └── unicode-xid (0.0.4)
└── unicode-xid (0.0.4) |
Gotta love minimal test cases. Thank you! |
I have reproduced the error with your minimal test case using GCC 6.3.0 on Ubuntu so it doesn't seem to be tied to Arch or GCC 7.
|
|
Now if we could apply no-pie to only the project and subprojects instead of dependencies that could solve it.. I figure I'm right in this is down to proc-macros having to be dynamically linked? https://github.com/rust-lang/rfcs/blob/master/text/1566-proc-macros.md UPDATE: |
Looking into revisiting this, this week. Was there a linker based issue in rustc related to this? I seem to remember seeing something but can't find it again for the life of me |
Maybe rust-lang/rust#43486, although it's unrelated? Anyway, according to the GCC bug you linked, it's about having |
I've found it, it was rust-lang/rust#35061, which is open still. |
Just a thought, could forcing usage of the gold linker instead of ld sort this issue out potentially? @yodaldevoid any better ideas, because my other idea is to try and force a reordering of the args cause if ---enable-default-pie is before --static I don't think the issue occurs (think those are the two flags, I tried it out a few weeks ago so memory is a bit fuzzy). |
So, I won't be able to poke at this again until Friday at the earliest with Saturday being more likely. That said, here is a little summary of what the problem seems to be and what I have tried. We tell rust to compile everything without PIC or PIE. PIC is position independent code in general, where PIE is specifically applied to executables and only applies at link time. We don't want either so when we set a breakpoint we know that we are setting it for the right line of code or even setting it on code at all. Both are disabled by passing So, So, the problem is that we cannot pass Now, what are the options? (You thought I would say "So", didn't you?) Well, one would be to fix this internal to Internal to tarpaulin, I don't know of any options. There might be something we can change with how we are configuring Cargo that will Edit: Coming back to this, I'm not sure what you are talking about when it comes to a |
I got static and shared confused. Nothing to see here. Hmmm not looking promising, might have to suggest a patch to rustc. I'll have a play at some point but this might have to be shelved for now. |
I tried I also tried this: value.push_str("-C link-arg=-no-pie -C link-arg=-shared "); , the idea being to get a command line like $ ~/tarpaulin/target/release/cargo-tarpaulin tarpaulin -v --skip-clean
Running Tarpaulin
Compiling quote v0.3.15
Compiling bitflags v0.4.0
Compiling stable_deref_trait v1.0.0
Compiling unicode-xid v0.0.4
Compiling rustc-demangle v0.1.5
Compiling version v2.0.1
Compiling void v1.0.2
Compiling either v1.4.0
Compiling byteorder v0.5.3
Compiling utf8-ranges v0.1.3
Compiling byteorder v1.1.0
Compiling log v0.3.8
Compiling utf8-ranges v1.0.0
Compiling regex-syntax v0.4.1
Compiling rust-stemmers v0.1.0
Compiling regex-syntax v0.3.9
Compiling num-traits v0.1.40
Compiling serde v1.0.20
Compiling crossbeam v0.3.0
Compiling winapi v0.2.8
Compiling bit-vec v0.4.4
Compiling libc v0.2.33
Compiling cfg-if v0.1.2
Compiling itoa v0.3.4
Compiling futures v0.1.17
Compiling maplit v0.1.6
Compiling lazy_static v0.1.16
Compiling lazy_static v0.2.10
Compiling winapi-build v0.1.1
Compiling dtoa v0.4.2
Compiling cc v1.0.3
Compiling bitflags v0.5.0
Compiling getopts v0.2.15
Compiling semver v0.1.20
Compiling gcc v0.3.54
Compiling ascii v0.7.1
Compiling synom v0.11.3
Compiling owning_ref v0.3.3
Compiling unreachable v1.0.0
Compiling itertools v0.5.10
Compiling bit-set v0.4.0
Compiling time v0.1.38
Compiling rand v0.3.18
Compiling num_cpus v1.7.0
Compiling memchr v1.0.2
Compiling tinysegmenter v0.1.0
Compiling kernel32-sys v0.2.2
Compiling pulldown-cmark v0.0.8
Compiling backtrace-sys v0.1.16
Compiling tantivy v0.5.0-dev (file:///~/tantivy)
Compiling combine v2.5.2
Compiling rustc_version v0.1.7
Compiling syn v0.11.11
Compiling thread_local v0.3.4
Compiling serde_json v1.0.6
Compiling bincode v0.8.0
Compiling lz4-sys v1.8.0
Compiling futures-cpupool v0.1.7
Compiling aho-corasick v0.6.3
Compiling uuid v0.5.1
Compiling tempdir v0.3.5
error: failed to run custom build command for `kernel32-sys v0.2.2`
process didn't exit successfully: `~/tantivy/target/debug/build/kernel32-sys-9e6da616b79a58fb/build-script-build` (signal: 11, SIGSEGV: invalid memory reference)
warning: build failed, waiting for other jobs to finish...
Error: failed to compile: build failed
Error during run
$ ~/tarpaulin/target/release/cargo-tarpaulin tarpaulin -v --skip-clean
Running Tarpaulin
Compiling nix v0.7.0
Compiling chan v0.1.19
Compiling tempfile v2.2.0
Compiling kernel32-sys v0.2.2
Compiling lz4-sys v1.8.0
Compiling backtrace-sys v0.1.16
Compiling serde_derive_internals v0.17.0
Compiling skeptic v0.9.0
Compiling regex v0.2.2
Compiling fs2 v0.2.5
Compiling backtrace v0.3.4
error: failed to run custom build command for `nix v0.7.0`
process didn't exit successfully: `~/tantivy/target/debug/build/nix-78fb40fa3c7fe661/build-script-build` (signal: 11, SIGSEGV: invalid memory reference)
warning: build failed, waiting for other jobs to finish...
Error: failed to compile: build failed
Error during run
$ ~/tarpaulin/target/release/cargo-tarpaulin tarpaulin -v --skip-clean
Running Tarpaulin
Compiling serde_derive v1.0.20
Compiling nix v0.7.0
Compiling env_logger v0.4.3
Compiling lz4 v1.22.0
Compiling error-chain v0.8.1
error: failed to run custom build command for `lz4 v1.22.0`
process didn't exit successfully: `~/tantivy/target/debug/build/lz4-45ede134a9e593fe/build-script-build` (signal: 11, SIGSEGV: invalid memory reference)
warning: build failed, waiting for other jobs to finish...
$ ~/tarpaulin/target/release/cargo-tarpaulin tarpaulin -v --skip-clean
Running Tarpaulin
Compiling atomicwrites v0.1.3
Compiling memmap v0.4.0
Compiling lz4 v1.22.0
Compiling fst v0.1.38
Compiling tantivy v0.5.0-dev (file:///~/tantivy)
Finished dev [unoptimized + debuginfo] target(s) in 103.54 secs
Processing tantivy
Launching test
running ~/tantivy/target/debug/deps/tantivy-eaddc236195dfb6a
ERROR: Tarpaulin cannot find code addresses check that pie is disabled for your linker. If linking with gcc try adding -C link-args=-no-pie to your rust flags |
To use a different linker than the default you need to set the linker value of your target triple. Please see here http://doc.crates.io/config.html#configuration-keys. Please note that that setting is set in one of Cargo's config files, NOT Cargo.toml. Please try that if you have not already. |
I'm not sure how that works. If I understand correctly, |
Ok, taking a step back here, what were you trying to achieve by using the |
Gold linker was tried add my suggestion as an unlikely but hopeful gamble on the tantivy issue linked above. I thought that might happen but you never know till you try |
What is the current status on this issue? Does anybody from the rustc team actually know about this problem? |
Looking at rust-lang/rust#35061, it looks like a fix for this very issue was merged in yesterday. It should be tested again. |
It looks like some of my code might even be able to be yanked out from the commits. |
I will test it on my project now, it looks like this fix should be in current nightly |
Well then, fingers crossed 🤞 |
rust-lang/rust#48076 is merged in! Can someone affected by this please update their nightly and see if it fixes the issue? Dunno about anyone else but I'm feeling mildly excited 🎉 |
Still Although, in one of my apps I'm seeing the following additional failure now:
Not sure if it's related though. Edit: took a look, seems like the ICE is somewhat related since it's due to Will check again once the next nightly comes out. |
If I understand it correctly, the change is not in nightly at the moment. Latest nightly is 24/02/18 now. |
Guess I might have got a bit overexcited... EDIT: @Libbum internal compiler errors should be reported to the rust team if they haven't already. Have a search of the issues and if you can't find it raise an issue 👍 |
I'm currently blocked on a link-dead-code bug (rust-lang/rust#45629, according to async-rs/futures-timer#2). If I disable whatever depends on
|
My log:
|
@vitvakatu is that with latest nightly? |
|
rust-lang/rust#48076 was merged 2 days ago, is there a chance it didn't make it to the nightly release on the 25th but is in the 26th? I don't know exactly how nightly releases work on the rust compiler so might be a stupid question. If it's definitely not sorted by this I'll start looking at getting a qemu instance that recreates the issue and the steps to work on the compiler to fix this. |
Docker might also work with a bit of prodding to enable And it can also pe used to run |
Checked with nightly 2018-02-26, the same result |
@vitvakatu what distro are you running? I'll use that as the starting point to try and recreate this at some point |
Still the same here, Arch Linux
|
also getting error:
Using trusty x86_64 and rust stable 1.24. Tried beta and nightly too. |
I'm running Arch linux |
Perhaps useful:
|
This seems to happen on Travis CI (trusty) as well: https://travis-ci.org/djc/quinn/jobs/383789849 That apparently has gcc-4.8.4. |
Similar to the above issue on Travis, I'm seeing this happening when running
The same happens with the |
Hello all, I've reproduced this and I think @yodaldevoid's analysis is right on the money. The reason this still isn't working is because you are manually adding If you rip our your code that adds -no-pie it works (with recent versions of rust that know about -no-pie). |
I for one am not setting any rustflags in my build. I assume |
Tarpaulin sets it so the addresses of lines read from dwarf match what's loaded. You can comment it out in |
I've just merged in a PR to fix this. All looks good my end, travis is just publishing 0.6.1 as we speak. Thank you @yodaldevoid |
I tried running an internal project through tarpaulin today and it appears to fail in the link stage. I'm not really sure what's going on here, but it does work inside an ubuntu xenial docker container on the same project (running docker in --privileged mode to work around ASLR errors from lacking EPERM), so I'm guessing it's something to do with gcc7.
Here is the output after all the Compiling lines:
system:
$ uname -a Linux kjttks 4.12.3-1-ARCH #1 SMP PREEMPT Sat Jul 22 15:32:02 UTC 2017 x86_64 GNU/Linux $ rustc --version rustc 1.19.0 (0ade33941 2017-07-17) $ cargo tarpaulin --version cargo-tarpaulin version: 0.3.9 $ cc -Q -v Using built-in specs. COLLECT_GCC=cc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp Thread model: posix gcc version 7.1.1 20170630 (GCC)
The text was updated successfully, but these errors were encountered: