Jimmy Stone
Jimmy Stone

Reputation: 121

Using gcc 13.1.0 to Run Test Coverage in Freestanding Environments

All

I am trying to follow the gcov tuturial on my Ubuntu 20.04

And I update my gcc to gcc 13.1.0 with

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt install gcc-13

Then I try to build the tutorial code with

gcc-13 --coverage -fprofile-info-section -c main.c
gcc-13 --coverage -fprofile-info-section -c app.c

ld --verbose | sed '1,/^===/d' | sed '/^===/d' > linkcmds

gcc-13 --coverage main.o app.o -T linkcmds -Wl,-Map,app.map

Then I got this error, and I check app.map, there is no __gcov_info_start and __gcov_info_end, which the tutorial mentioned.

/usr/bin/ld: main.o: in function dump_gcov_info': main.c:(.text+0x1df): undefined reference to __gcov_info_start' /usr/bin/ld: main.c:(.text+0x1ea): undefined reference to `__gcov_info_end' collect2: error: ld returned 1 exit status

I found there is a message, saying

As-needed library included to satisfy reference by file (symbol)

libc.so.6                     /usr/lib/gcc/x86_64-linux-gnu/13/libgcov.a(_gcov.o) (exit@@GLIBC_2.2.5)
main.o: dynamic relocation against `__gcov_info_start' in read-only section `.text'

Anything I miss?

Upvotes: 0

Views: 134

Answers (1)

Jimmy Stone
Jimmy Stone

Reputation: 121

All

I found I miss one step in the tutorial. After this step

ld --verbose | sed '1,/^===/d' | sed '/^===/d' > linkcmds

I need add the .gcov_info section after .rodata in the linkcmds

  .gcov_info      :
  {
    PROVIDE (__gcov_info_start = .);
    KEEP (*(.gcov_info))
    PROVIDE (__gcov_info_end = .);
  }

Upvotes: 0

Related Questions