LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 48282 - --cref on ld.lld writes the cref table to stdout even with -Map=filename
Summary: --cref on ld.lld writes the cref table to stdout even with -Map=filename
Status: RESOLVED INVALID
Alias: None
Product: lld
Classification: Unclassified
Component: ELF (show other bugs)
Version: unspecified
Hardware: PC All
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-24 06:00 PST by Jan Martin Mikkelsen
Modified: 2021-03-05 23:41 PST (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments
Patch to use the file from -Map as a target for --cref output. (1.47 KB, patch)
2020-11-24 06:00 PST, Jan Martin Mikkelsen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Martin Mikkelsen 2020-11-24 06:00:29 PST
Created attachment 24204 [details]
Patch to use the file from -Map as a target for --cref output.

The --cref option on ld.lld only seems to write to stdout, ignoring the -Map=filename option. This is a change from GNU ld.

To reproduce, compile and link any code with --cref, for example:

    echo 'int main() { return 0; }' > test.c
    cc -Wl,-Map=test.map -Wl,--cref test.c

The cross reference table is emitted on stdout instead of being written to test.map.

A patch (against the lld imported into the FreeBSD 12.2 tree) that resolves the issue for me is attached.
Comment 1 Fangrui Song 2020-11-28 19:17:43 PST
GNU ld's documentation

--cref

Output a cross reference table. If a linker map file is being generated, the cross reference table is printed to the map file. Otherwise, it is printed on the standard output.

---

The code was there in 1990+. The behavior looks strange.
Comment 2 Jan Martin Mikkelsen 2021-03-05 23:41:38 PST
I'm curious about what was invalid about this.

Your comment said that GNU ld prints --cref output to the map file if a map file is specified, stdout otherwise. That is also the behaviour I have observed with GNU ld for many year.

That isn't what lld is doing.

I read your comment as supporting this as a bug. Was I mistaken?