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

How can I stop rustc including system specific information such as absolute file paths of the source it's compiled from in the binaries it generates? #40374

Closed
ghost opened this issue Mar 8, 2017 · 18 comments
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ghost
Copy link

ghost commented Mar 8, 2017

/checkout/src/libcore/option.rs
/home/kfairmasterz/.cargo/registry/src/github.com-1ecc6299db9ec823/typeable-0.1.2/src/lib.rs
/home/kfairmasterz/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.7/src/ssl/bio.rs

@steveklabnik steveklabnik added the A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) label Mar 8, 2017
@ghost ghost changed the title How terminate the backtrace filepath like /checkout/src/libcore/slice.rs This such of debug info? How terminate the backtrace filepath like /checkout/src/libcore/slice.rs This such of debug info from compiled rlib or bin? Mar 8, 2017
@ghost ghost changed the title How terminate the backtrace filepath like /checkout/src/libcore/slice.rs This such of debug info from compiled rlib or bin? No way to wipe out panic message from compiled rust binary/rlib. Mar 9, 2017
@ghost
Copy link
Author

ghost commented Mar 9, 2017

I tried: -Cdebuginfo=0 -Zno-landing-pads -C opt-level=3 -C panic=abort -C lto

It still exists panic message in binary:

╭─kfairmasterz@Android /tmp/tst  ‹master*› 
╰─➤  LC_ALL=en_US.UTF8 grep -in "checkout" target/i686-unknown-linux-gnu/release/tst infomation
Binary file target/i686-unknown-linux-gnu/release/tst matches
╭─kfairmasterz@Android /tmp/tst  ‹master*› 
╰─➤  LC_ALL=en_US.UTF8 grep -in "home/kfairmasterz" target/i686-unknown-linux-gnu/release/tst
Binary file target/i686-unknown-linux-gnu/release/tst matches

What should I do?

@ghost
Copy link
Author

ghost commented Mar 9, 2017

I see, they are hardcoded in libstd.

https://doc.rust-lang.org/nightly/src/std/macros.rs.html#39-60

#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow_internal_unstable]
macro_rules! panic {
    () => ({
        panic!("explicit panic")
    });
    ($msg:expr) => ({
        $crate::rt::begin_panic($msg, {
            // static requires less code at runtime, more constant data
            static _FILE_LINE: (&'static str, u32) = (file!(), line!());
            &_FILE_LINE
        })
    });
    ($fmt:expr, $($arg:tt)+) => ({
        $crate::rt::begin_panic_fmt(&format_args!($fmt, $($arg)+), {
            // The leading _'s are to avoid dead code warnings if this is
            // used inside a dead function. Just `#[allow(dead_code)]` is
            // insufficient, since the user may have
            // `#[forbid(dead_code)]` and which cannot be overridden.
            static _FILE_LINE: (&'static str, u32) = (file!(), line!());
            &_FILE_LINE
        })
    });
}

https://doc.rust-lang.org/nightly/src/core/macros.rs.html#15-31

#[macro_export]
#[allow_internal_unstable]
#[stable(feature = "core", since = "1.6.0")]
macro_rules! panic {
    () => (
        panic!("explicit panic")
    );
    ($msg:expr) => ({
        static _MSG_FILE_LINE: (&'static str, &'static str, u32) = ($msg, file!(), line!());
        $crate::panicking::panic(&_MSG_FILE_LINE)
    });
    ($fmt:expr, $($arg:tt)*) => ({
        // The leading _'s are to avoid dead code warnings if this is
        // used inside a dead function. Just `#[allow(dead_code)]` is
        // insufficient, since the user may have
        // `#[forbid(dead_code)]` and which cannot be overridden.
        static _FILE_LINE: (&'static str, u32) = (file!(), line!());
        $crate::panicking::panic_fmt(format_args!($fmt, $($arg)*), &_FILE_LINE)
    });
}

I know how to fix it for now.

@ghost ghost closed this as completed Mar 9, 2017
@ghost ghost reopened this Mar 9, 2017
@ghost
Copy link
Author

ghost commented Mar 9, 2017

No, It's doesn't work. I had to find another way out.


command:
: , ^@^@^@^@^@^@^@^@^@^@^@^@SizedReader(remaining=)^@^@^@^@^@^@^@^@^@ChunkedReader(chunk_remaining=un
known)^@^@^@^@^@^@^@^@^@^@ChunkedReader(chunk_remaining=EofReaderEmptyReaderThroughWriterChunkedWrite
r^@^@^@^@SizedWriter(remaining=EmptyWriter^M
Host^@^@^@^@^@^@^@^@^@/home/kfairmasterz/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rust
lib/src/rust/src/libcollections/vec.rs^@^@^@^@^@^@^@^@^@^@^@internal error: entered unreachable code^
@^@^@^@^@^@^@^@raw_capacity overflow^@^@^@^@^@^@^@^@^@^@^@capacity overflowreserve overflowraw_cap ov
erflow^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@assertion failed: self.table.size() <= new_raw_cap^@^@^@^@^@^@^@^
@^@^@^@^@^@^@assertion failed: new_raw_cap.is_power_of_two() || new_raw_cap == 0: hostnameportNoneSom
e^@^@^@^@^@^@^@stream did not contain valid UTF-8^@^@^@^@^@^@^@^@^@^@^@^@^@^@/home/kfairmasterz/.rust
up/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/io/impls.rs^@^@^@^@^@^
@^@^@^@^@^@^@^@^@failed to write the buffered dataHttp11Messageis_proxiedmethodstreamWrapperobjIdleWr
itingReadingBox<NetworkStream>OptionsGetPostPutDeleteHeadTraceConnectPatchExtension^@^@^@^@^@^@^@^@^@
Transfer-Encoding^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@item.raw must existContent-Length^@^@^@^@^@^@^@^@^@^@^
@^@^@^@^@a Display implementation return an error unexpectedly^@^@^@^@^@^@^@^@^@^@^@not PtrMap::One v
alue, EmptyOneManyContentLength^D^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@^B^@^@^@^C^@^@^@^H^@^@
^@^G^@^@^@^G^@^@^@^G^@^@^@^G^@^@^@^D^@^@^@^G^@^@^@^H^@^@^@,^F^@^@D^F^@^@ ^@^@^@,^F^@^@D^F^@^@'^F^@^@D
^F^@^@G^F^@^@^@^C^@^@¦^^^@^@^A^C^@^@¤^^^@^@^C^C^@^@ª^^^@^@     ^C^@^@¨^^^@^@^@^C^@^@À^^^@^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ationNo ContentReset ContentPartial ContentMulti-StatusAlready ReportedIM UsedMultiple Choices^@^@^@^
@^@^@^@^@^@^@Moved PermanentlyFoundSee OtherNot ModifiedUse Proxy^@^@^@^@^@^@^@^@^@^@^@^@Temporary Re
direct^@^@^@^@^@^@^@^@^@^@^@^@^@^@Permanent RedirectBad RequestUnauthorizedPayment RequiredForbiddenN
ot Found^@^@^@^@^@Method Not AllowedNot AcceptableProxy Authentication RequiredRequest TimeoutConflic
tGoneLength Required^@^@^@^@^@^@^@^@^@Precondition Failed^@^@^@^@^@^@^@^@^@^@^@^@^@Payload Too LargeU
RI Too Long^@^@^@Unsupported Media Type^@^@^@^@^@^@^@^@^@^@Range Not Satisfiable^@^@^@^@^@^@^@^@^@^@^
@Expectation FailedI'm a teapot^@^@Misdirected Request^@^@^@^@^@^@^@^@^@^@^@^@^@Unprocessable EntityL
@@@                                                                                                  
<u/release/deps/tst-55c0f628e60214f1" [noeol][converted] 3861L, 1142827C                                                                                                              

@ghost ghost changed the title No way to wipe out panic message from compiled rust binary/rlib. No way to wipe out some strange local file path from compiled rust binary/rlib. Mar 9, 2017
@ghost
Copy link
Author

ghost commented Mar 9, 2017

Almost I am given up. The strange local source file path string where are they come from?
https://github.com/kfairmasterz/wtf

https://www.reddit.com/r/rust/comments/5ygehg/when_i_opened_a_rustc_compiled_binary_that/

@steveklabnik
Copy link
Member

It is unclear what your question is. These paths point to where things were compiled, which in the case of libstd, is not on your computer, but on our build machines.

@ghost
Copy link
Author

ghost commented Mar 9, 2017

How to do not let rustc writing that local source file path string in the final compiled binary program?

I am sorry about the unclear question.

@steveklabnik
Copy link
Member

I believe you can run strip; I am not aware of a flag or anything to turn this off, though I may be wrong.

@ghost
Copy link
Author

ghost commented Mar 9, 2017

@steveklabnik I tried. it didn't work.

cd /tmp
git clone https://github.com/kfairmasterz/wtf
cd wtf
cargo build --release
strip ./target/release/wtf
objdump -s -j .rodata ./target/release/wtf

@ghost ghost changed the title No way to wipe out some strange local file path from compiled rust binary/rlib. How to do not let rustc writing that local source file path string in the final compiled binary program? Mar 9, 2017
@alexcrichton
Copy link
Member

These paths are coming through calls to panic! most likely, and cannot be stripped out easily. Currently there is no way to instruct the panic macro to not encode local paths.

@ghost ghost changed the title How to do not let rustc writing that local source file path string in the final compiled binary program? How can I stop rustc including system specific information such as absolute file paths of the source it's compiled from in the binaries it generates? Mar 9, 2017
@ghost
Copy link
Author

ghost commented Mar 10, 2017

@alexcrichton I tried mask the macro {libcore,libstd}/panic! inside file! line as "" 0, Then xargo build --release, objdump -s -j .rodata target/release/binary, it still exists such of path strings.

After I will upload a sample repo.

@ghost
Copy link
Author

ghost commented Mar 10, 2017

https://github.com/kfairmasterz/hello_https/tree/master
There is. (Sample repository)

Now, /home/kfairmasterz/.cargo/registry/src/github.com-1ecc6299db9ec823/unicode-normalization-0.1.4/src/tables.rs(link) doesn't exists any about panic! but this path string still exists in ./target/i686-unknown-linux-gnu/release/hello_https

(or objdump -s -j .rodata target/i686-unknown-linux-gnu/release/hello_https)
(or vim target/i686-unknown-linux-gnu/release/hello_https)

I wondering where are they come from.

@rohitjoshi
Copy link
Contributor

👍

@ghost
Copy link
Author

ghost commented Mar 12, 2017

Unfortunately, Nobody one tries tell me there is better way how to do.

LLVM IR

@ghost
Copy link
Author

ghost commented Mar 12, 2017

Now I see How to solve it now.

These path definely is from panic messages.

Now, I could focus to wipe out these messages.

@ghost
Copy link
Author

ghost commented Mar 12, 2017

As finally trace out, I believe there is the source code about how inject the local source file location now.
https://github.com/rust-lang/rust/blob/master/src/librustc_trans/mir/block.rs#L279-L327

https://github.com/rust-lang/rust/blob/master/src/librustc_trans/mir/block.rs#L284-L287 Specifically.
Question is, How to modify it.

@ghost
Copy link
Author

ghost commented Mar 12, 2017

Oh I see hints for define a option/flag;
https://github.com/rust-lang/rust/blob/master/src/librustc_trans/mir/block.rs#L123
if !bcx.sess().target.target.options.custom_unwind_resume {

@ghost
Copy link
Author

ghost commented Mar 13, 2017

@steveklabnik
Copy link
Member

Great, let's close then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants