Skip to content

-Wl,--gc-sections removes codecov related symbols #543

@mati865

Description

@mati865

Forwarding taiki-e/cargo-llvm-cov#254 (comment) here with a simple C reproducer.

Code:

#include <stdio.h>

int main(){
  printf("Hello");
  return 0;
}
  1. Running without --gc-sections:
$ clang hello.c -fprofile-instr-generate -fcoverage-mapping

$ ./a.exe
Hello

$ llvm-profdata merge -sparse default.profraw -o hello.profdata

$ llvm-cov show a.exe -instr-profile=hello.profdata
    1|       |#include <stdio.h>
    2|       |
    3|      1|int main(){
    4|      1|  printf("Hello");
    5|      1|  return 0;
    6|      1|}
  1. Running the same commands with --gc-sections:
$ clang hello.c -fprofile-instr-generate -fcoverage-mapping -Wl,--gc-sections

$ ./a.exe
Hello

$ llvm-profdata merge -sparse default.profraw -o hello.profdata

$ llvm-cov show a.exe -instr-profile=hello.profdata

(llvm-cov show prints nothing)

  1. Reusing .profdata and .profraw from step 2 and binary without sections GC:
$ clang hello.c -fprofile-instr-generate -fcoverage-mapping

$ llvm-cov show a.exe -instr-profile=hello.profdata
warning: a.exe: profile data may be out of date - object is newer
    1|       |#include <stdio.h>
    2|       |
    3|      1|int main(){
    4|      1|  printf("Hello");
    5|      1|  return 0;
    6|      1|}

Only 2nd step is missing coverage info, which leads me to believe llvm-cov is looking for a symbol or section removed by --gc-sections. Especially removal of .lcovfun section by section GC is suspicious.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions