xd009642 / llvm-embedded-coverage

Use llvm coverage instrumentation on embedded targets
Apache License 2.0
1 stars 0 forks source link

Linker shenanigans #1

Open xd009642 opened 2 years ago

xd009642 commented 2 years ago

On the feat/make-no-std when trying to flash my device I get:

     Erasing sectors ⠁ [00:00:00] [############################################################################################################################################]       0B/      0B @       0B/s (eta 0s )
       Error failed to flash /home/daniel/personal/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/llvm-embedded-coverage

             Caused by:
                 0: Error while flashing
                 1: No flash memory contains the entire requested memory range 0x00010000..   0x104e5.

Now the binary is <1MB, and the flash of the chip I'm using is 2MB so it appears there's something wrong in my linker args or linker scripts. But it's been a good few years since I've touched rust embedded and nothing appears off to me...

@newAM have you had a chance to try this out and do you know how I could solve this? I've tried looking it up with cargo flash and cargo embed but not found anything helpful as of yet

newAM commented 2 years ago

I got an entirely different set of linker shenanigans compiling that branch, unfortunately I don't have time to dig in right now :(

  = note: rust-lld: error: /home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libminicov-4c01edf3db0477f9.rlib(InstrProfiling.o) is incompatible with /home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/llvm_embedded_coverage-99dc7a9194551c00.3x19h158c8n8aufg.rcgu.o
          rust-lld: error: /home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libminicov-4c01edf3db0477f9.rlib(InstrProfilingBuffer.o) is incompatible with /home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/llvm_embedded_coverage-99dc7a9194551c00.3x19h158c8n8aufg.rcgu.o
          rust-lld: error: /home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libminicov-4c01edf3db0477f9.rlib(InstrProfilingMerge.o) is incompatible with /home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/llvm_embedded_coverage-99dc7a9194551c00.3x19h158c8n8aufg.rcgu.o

Is your cargo flash / cargo embed up to date? I have had updates fix flashing problems before.

xd009642 commented 2 years ago

I'll try them in a bit. Were you setting the rust flags when building? RUSTFLAGS="-Zinstrument-coverage -Zno-profiler-runtime"? Building works fine for me it's just it seems to not be laid out right for flashing.

The fact the llvm_prf_cnts and llvm_prf_data sections need to be r/w to record the coverage data might be a cause I'm thinking :thinking:

xd009642 commented 2 years ago

Tried updating them and no luck. I'm thinking it must not be seeing my memory.x for some reason because " 0x00010000.. 0x104e5." is not the memory region I want at all :|

xd009642 commented 2 years ago

I might have to shelve this for a bit if I don't make progress (at least until xmas holidays) it was kinda me procrastinating by working on something else instead of what I'm meant to be :sweat_smile:

newAM commented 2 years ago

I'll try them in a bit. Were you setting the rust flags when building? RUSTFLAGS="-Zinstrument-coverage -Zno-profiler-runtime"? Building works fine for me it's just it seems to not be laid out right for flashing.

The fact the llvm_prf_cnts and llvm_prf_data sections need to be r/w to record the coverage data might be a cause I'm thinking thinking

Yeah, I am not sure why it is not compiling for me. Are you on a similar nightly version?

$ git rev-parse HEAD                                                      
5be608de4e35605b7537bffdf496df55c5311ad9
$ cargo +nightly --version
cargo 1.58.0-nightly (7f08ace4f 2021-11-24)
Full Build Output... ```console $ cargo clean $ RUSTFLAGS="-Zinstrument-coverage -Zno-profiler-runtime" cargo +nightly build Compiling proc-macro2 v1.0.32 Compiling semver-parser v0.7.0 Compiling unicode-xid v0.2.2 Compiling syn v1.0.81 Compiling typenum v1.14.0 Compiling cortex-m v0.7.3 Compiling nb v1.0.0 Compiling semver v1.0.4 Compiling vcell v0.1.3 Compiling void v1.0.2 Compiling version_check v0.9.3 Compiling bitfield v0.13.2 Compiling same-file v1.0.6 Compiling defmt-parser v0.2.2 Compiling cortex-m-rt v0.6.15 Compiling stable_deref_trait v1.2.0 Compiling cortex-m v0.6.7 Compiling cc v1.0.72 Compiling r0 v0.2.2 Compiling cortex-m-semihosting v0.3.7 Compiling ufmt-write v0.1.0 Compiling llvm-embedded-coverage v0.1.0 (/home/alex/git/llvm-embedded-coverage) Compiling cfg-if v1.0.0 Compiling panic-halt v0.2.0 Compiling nb v0.1.3 Compiling volatile-register v0.2.1 Compiling walkdir v2.3.2 Compiling semver v0.9.0 Compiling embedded-hal v0.2.6 Compiling generic-array v0.14.4 Compiling rustc_version v0.2.3 Compiling bare-metal v0.2.5 Compiling defmt v0.2.3 Compiling minicov v0.2.2 Compiling quote v1.0.10 Compiling generic-array v0.13.3 Compiling generic-array v0.12.4 Compiling rtt-target v0.3.1 Compiling as-slice v0.1.5 Compiling aligned v0.3.5 Compiling defmt-macros v0.2.3 Compiling cortex-m-rt-macros v0.6.15 Compiling defmt-test-macros v0.2.1 Compiling defmt-rtt v0.2.0 Compiling defmt-test v0.2.3 error: linking with `rust-lld` failed: exit status: 1 | = note: "rust-lld" "-flavor" "gnu" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/llvm_embedded_coverage-422c1a2eb8190435.1gnl16dmz851w71w.rcgu.o" "--as-needed" "-L" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps" "-L" "/home/alex/git/llvm-embedded-coverage/target/debug/deps" "-L" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/build/cortex-m-78743fa8465f0c61/out" "-L" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/build/cortex-m-rt-f1a3d6a8ddc5ca0e/out" "-L" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/build/cortex-m-semihosting-d622abfdb4beb985/out" "-L" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/build/defmt-33dc332803fe4b0f/out" "-L" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/build/minicov-a45e2304e5d65653/out" "-L" "/home/alex/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7em-none-eabihf/lib" "-Bstatic" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libminicov-e07d21c8b696224e.rlib" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libcfg_if-ed9af3ef0fb0500d.rlib" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/librtt_target-c9177c23c05e5d21.rlib" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libcortex_m-d962a26cbcfaf3a6.rlib" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libembedded_hal-5a64baad222ea878.rlib" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libvoid-e245d597db37bba7.rlib" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libnb-2153bd107d507d8d.rlib" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libnb-0f2968f351785e3b.rlib" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libvolatile_register-a2a6ec7e983eb9bb.rlib" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libvcell-861062d5242e30aa.rlib" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libbare_metal-5e3367dd91bb6c30.rlib" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libufmt_write-d785522930dc655c.rlib" "--start-group" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libpanic_halt-a90c36ef06bbfc94.rlib" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libcortex_m_rt-549ad210761229c1.rlib" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libr0-f9908adae0ed5eba.rlib" "/home/alex/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7em-none-eabihf/lib/librustc_std_workspace_core-9ae03c706dab5b95.rlib" "/home/alex/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7em-none-eabihf/lib/libcore-4c81109e506dada5.rlib" "--end-group" "/home/alex/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7em-none-eabihf/lib/libcompiler_builtins-aef8f029b4258cbf.rlib" "-Bdynamic" "--eh-frame-hdr" "-znoexecstack" "-L" "/home/alex/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7em-none-eabihf/lib" "-o" "/home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/llvm_embedded_coverage-422c1a2eb8190435" "--gc-sections" "-u" "__llvm_profile_runtime" = note: rust-lld: error: /home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libminicov-e07d21c8b696224e.rlib(InstrProfiling.o) is incompatible with /home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/llvm_embedded_coverage-422c1a2eb8190435.1gnl16dmz851w71w.rcgu.o rust-lld: error: /home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libminicov-e07d21c8b696224e.rlib(InstrProfilingBuffer.o) is incompatible with /home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/llvm_embedded_coverage-422c1a2eb8190435.1gnl16dmz851w71w.rcgu.o rust-lld: error: /home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libminicov-e07d21c8b696224e.rlib(InstrProfilingMerge.o) is incompatible with /home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/llvm_embedded_coverage-422c1a2eb8190435.1gnl16dmz851w71w.rcgu.o rust-lld: error: /home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/libminicov-e07d21c8b696224e.rlib(InstrProfilingPlatformLinux.o) is incompatible with /home/alex/git/llvm-embedded-coverage/target/thumbv7em-none-eabihf/debug/deps/llvm_embedded_coverage-422c1a2eb8190435.1gnl16dmz851w71w.rcgu.o error: could not compile `llvm-embedded-coverage` due to previous error ```
xd009642 commented 2 years ago

So there's only 2 days between our nightly versions... Let me update nightly and see if it builds

git rev-parse HEAD
5be608de4e35605b7537bffdf496df55c5311ad9
cargo +nightly --version
cargo 1.58.0-nightly (e1fb17631 2021-11-22) 
xd009642 commented 2 years ago

I removed flip-link thinking it was down to https://github.com/knurling-rs/flip-link/issues/43 and then flashed it... But then I realised I forgot to set rustflags and then set them and it failed to flash. But apparently the binary is smaller - which shouldn't be the case as there should be more due to the coverage counter sections etc :thinking:

Without RUSTFLAGS="-Zinstrument-coverage -Zno-profiler-runtime" text data bss dec hex filename 10892 8 9560 20460 4fec llvm-embedded-coverage

Sections:

Idx Name Size VMA LMA File off Algn
0 .vector_table 00000400 08000000 08000000 00010000 2**2
CONTENTS ALLOC, LOAD, READONLY, DATA
1 .text 00002224 08000400 08000400 00010400 2**1
CONTENTS ALLOC, LOAD, READONLY, CODE
2 .rodata 00000468 08002624 08002624 00012624 2**4
CONTENTS ALLOC, LOAD, READONLY, DATA
3 .data 00000008 200001b8 08002a90 000201b8 2**3
CONTENTS ALLOC, LOAD, DATA
4 .bss 00002558 200001c0 200001c0 000201c0 2**3
ALLOC
5 .uninit 00000000 20002718 20002718 000201c0 2**2
ALLOC
6 .debug_loc 000035ec 00000000 00000000 000201c0 2**0
CONTENTS READONLY, DEBUGGING
7 .debug_abbrev 000023d4 00000000 00000000 000237ac 2**0
CONTENTS READONLY, DEBUGGING
8 .debug_info 0002d864 00000000 00000000 00025b80 2**0
CONTENTS READONLY, DEBUGGING
9 .debug_aranges 00002110 00000000 00000000 000533e8 2**3
CONTENTS READONLY, DEBUGGING
10 .debug_ranges 0001a6b8 00000000 00000000 000554f8 2**0
CONTENTS READONLY, DEBUGGING
11 .debug_str 00036ec2 00000000 00000000 0006fbb0 2**0
CONTENTS READONLY, DEBUGGING
12 .debug_pubnames 0000f2ec 00000000 00000000 000a6a72 2**0
CONTENTS READONLY, DEBUGGING
13 .debug_pubtypes 0000222e 00000000 00000000 000b5d5e 2**0
CONTENTS READONLY, DEBUGGING
14 .ARM.attributes 0000003a 00000000 00000000 000b7f8c 2**0
CONTENTS READONLY
15 .debug_frame 0000705c 00000000 00000000 000b7fc8 2**2
CONTENTS READONLY, DEBUGGING
16 .debug_line 0002a89e 00000000 00000000 000bf024 2**0
CONTENTS READONLY, DEBUGGING
17 .debug_macinfo 00000007 00000000 00000000 000e98c2 2**0
CONTENTS READONLY, DEBUGGING
18 .comment 000000a3 00000000 00000000 000e98c9 2**0
CONTENTS READONLY

With RUSTFLAGS="-Zinstrument-coverage -Zno-profiler-runtime" text data bss dec hex filename 1688 3268 0 4956 135c target/thumbv7em-none-eabihf/debug/llvm-embedded-coverage

Sections:

Idx Name Size VMA LMA File off Algn
0 .ARM.exidx 00000010 00010134 00010134 00000134 2**2
CONTENTS ALLOC, LOAD, READONLY, DATA
1 __llvm_prf_names 000003a2 00010144 00010144 00000144 2**0
CONTENTS ALLOC, LOAD, READONLY, DATA
2 .text 000002e6 000204e6 000204e6 000004e6 2**1
CONTENTS ALLOC, LOAD, READONLY, CODE
3 .init_array 00000014 000307cc 000307cc 000007cc 2**2
CONTENTS ALLOC, LOAD, DATA
4 __llvm_prf_cnts 00000490 000407e0 000407e0 000007e0 2**3
CONTENTS ALLOC, LOAD, DATA
5 __llvm_prf_data 00000820 00040c70 00040c70 00000c70 2**3
CONTENTS ALLOC, LOAD, DATA
6 __llvm_covfun 000009fa 00000000 00000000 00001490 2**3
CONTENTS READONLY
7 __llvm_covmap 000001cc 00000000 00000000 00001e90 2**3
CONTENTS READONLY
8 .debug_loc 00002ef3 00000000 00000000 0000205c 2**0
CONTENTS READONLY, DEBUGGING
9 .debug_abbrev 00002110 00000000 00000000 00004f4f 2**0
CONTENTS READONLY, DEBUGGING
10 .debug_info 0002bbcb 00000000 00000000 0000705f 2**0
CONTENTS READONLY, DEBUGGING
11 .debug_aranges 000020a0 00000000 00000000 00032c30 2**3
CONTENTS READONLY, DEBUGGING
12 .debug_ranges 0001a668 00000000 00000000 00034cd0 2**0
CONTENTS READONLY, DEBUGGING
13 .debug_str 00037061 00000000 00000000 0004f338 2**0
CONTENTS READONLY, DEBUGGING
14 .debug_pubnames 0000efef 00000000 00000000 00086399 2**0
CONTENTS READONLY, DEBUGGING
15 .debug_pubtypes 00001ed7 00000000 00000000 00095388 2**0
CONTENTS READONLY, DEBUGGING
16 .ARM.attributes 00000038 00000000 00000000 0009725f 2**0
CONTENTS READONLY
17 .debug_frame 0000719c 00000000 00000000 00097298 2**2
CONTENTS READONLY, DEBUGGING
18 .debug_line 0002a639 00000000 00000000 0009e434 2**0
CONTENTS READONLY, DEBUGGING
19 .debug_macinfo 00000007 00000000 00000000 000c8a6d 2**0
CONTENTS READONLY, DEBUGGING
20 .comment 000000a3 00000000 00000000 000c8a74 2**0
CONTENTS READONLY
xd009642 commented 2 years ago

Okay it flashes now, rustflags should have been in the .cargo/config to avoid overwriting some of the ones added by other things