Binary mode carries the previous function's source line into functions with no line info

Open Beginner friendly
#55 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
79/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, typescript
Domain
backend, tooling

Research direction

Start by reading the function-label handling in the binary-mode objdump parser and compare it with the TypeScript change in compiler-explorer/compiler-explorer#9306. Check how .L labels and function labels appear in the supplied real dump examples or parser tests. Done means clearing the current source at non-.L function labels, preserving source across .L labels, and confirming the mappings no longer leak into functions without line records.

Written by the indexing model from the issue text.

Description

In binary mode ("Link to binary"), a function with no line records of its own, such as statically linked glibc code built without debug info, inherits the last file:line of the function before it. objdump only prints a line record when the line changes, and the parser doesn't clear the current source at a new function label.

Reproduce on godbolt.org with x86-64 gcc 14.2 (cg142), C, with binary output on and the default filters:

int square(int num) {
    return num * num;
}

int main() { return square(3); }
  • With -O1 -g, everything is correct: 5 lines map to example.c, all in square and main.
  • With -O1 -g -static, 4688 of the 5001 lines map to example.c, across 76 glibc functions: init_cpu_features.constprop.0 810, update_active.constprop.0 326, get_common_cache_info.constprop.0 321, and so on. Only square and main should.

With a normal dynamic link it's hidden, because binaryHideFuncRe hides the CRT functions.

Fix: clear the current source at each function label, except assembler-local .L labels, which are inside a function (RISC-V keeps .Lpcrel_hi* in the symbol table). objdump -l prints a function's first line record after its label, so nothing correct is lost. CE's TypeScript parser got exactly this in compiler-explorer/compiler-explorer#9306:

func = match[2];
if (!func.startsWith('.L')) source = null;

That PR has the details and tests. The reviewer checked it against 24 real dumps (gcc and clang, -O0/-O2, with and without -g, -static, C and C++), and the mappings matched addr2line. Linux prod C/C++ uses this external parser (externalparser=CEAsmParser), so the TypeScript fix doesn't reach it.

🤖 Generated with Claude Code

Dominant language
C++
Stars
36
Forks
10
Avg merge
36m
Merged PRs (30d)
6

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from compiler-explorer/asm-parser

All issues in compiler-explorer/asm-parser

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.