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 get the symbol file when build command is 'ohrs build --arch aarch --release -- -Z build-std=std -Z build-std-features="optimize_for_size"' #26

Open
SaigyoujiNexas opened this issue Nov 18, 2024 · 9 comments

Comments

@SaigyoujiNexas
Copy link

SaigyoujiNexas commented Nov 18, 2024

I use command below to build my project as a dylib :
ohrs build --arch aarch --release -- -Z build-std=std -Z build-std-features="optimize_for_size"
and Cargo.toml below:

[package]
name = "im_rust_ts"
version.workspace = true
edition.workspace = true

[lib]
crate-type = ["cdylib"]

[dependencies]
lazy_static = { workspace = true }
log = { workspace = true }
once_cell = { workspace = true }
serde_json = { workspace = true }
serde = { workspace = true }
http = { workspace = true }
base64 = { workspace = true }
dyn-clone = { workspace = true }

napi = { workspace = true, optional = true }
napi-derive = { workspace = true, optional = true }
napi-ohos = { workspace = true, optional = true }
napi-derive-ohos = { workspace = true, optional = true }

[build-dependencies]
napi-build = { workspace = true, optional = true }
napi-build-ohos = { workspace = true, optional = true }

[profile.release]
lto = true
strip = true 

When I use the output .so file as other application component, the crash occured. I try to debug it, but the lack of symbol make me debug so hard because I can not locate which line crashed by use the objdump.

Copy link

@richerfu Please check this issue, thanks.

@richerfu
Copy link
Member

please build project without --release

@SaigyoujiNexas
Copy link
Author

SaigyoujiNexas commented Nov 18, 2024

please build project without --release

but I need provide my package to other team, I can not build a debug package, because it could make package size become huge

@richerfu
Copy link
Member

You can remove strip = true which is in your cargo.toml

@richerfu
Copy link
Member

These are some common solutions.
You need to set debug with Cargo.toml

[profile.release]
lto = true
strip = true
debug = true

And save your debug info with objcopy:

$OHOS_NDK_HOME/native/llvm/bin/llvm-objcopy --only-keep-debug ./dist/arm64-v8a/libhello.so ./hello.debug

In fact, this is a general solution for rust, which has nothing to do with ohos-rs itself.

@SaigyoujiNexas
Copy link
Author

SaigyoujiNexas commented Nov 19, 2024

These are some common solutions. You need to set debug with Cargo.toml

[profile.release]
lto = true
strip = true
debug = true

And save your debug info with objcopy:

$OHOS_NDK_HOME/native/llvm/bin/llvm-objcopy --only-keep-debug ./dist/arm64-v8a/libhello.so ./hello.debug

In fact, this is a general solution for rust, which has nothing to do with ohos-rs itself.

no, when I set

[profile.release]
strip = false
debug = true

in Cargo.toml, and use the below command to compile

ohrs build --arch aarch --release -- -Z build-std=std -Z build-std-features="optimize_for_size"

the objdump file is looks like that:
image

when I delete "--release", the package size become to 150MB, but the objdump file have all information I need.
image

@richerfu
Copy link
Member

You need to save your debug info with debug=true and use debug file to locate the source code. It's impossible for us to get the smallest binary size with source info.

@SaigyoujiNexas
Copy link
Author

You need to save your debug info with debug=true and use debug file to locate the source code. It's impossible for us to get the smallest binary size with source info.您需要使用debug=true保存调试信息并使用调试文件来定位源代码。我们不可能通过源信息获得最小的二进制大小。

I got. it could not have all debug info such as line number, and what rust code relative this asm code, which I just can relay on remaining debug info( struct name, method reference expression invoke, method signature etc. ) when compile by

ohrs build --release

right?

@richerfu
Copy link
Member

Yep

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

2 participants