Skip to content

zig cc: add linker -Map flag #18358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Conversation

jiridanek
Copy link

@jiridanek jiridanek commented Dec 23, 2023

Linker maps are a diagnostic/debugging feature. It causes the linker to write out memory ranges (similar to the runtime content of /proc/self/map on Linux) and some such info. I need this because a program I want to compile with zig cc uses this.

Fixes #18356

Comment on lines +2401 to +2445
} else if (mem.startsWith(u8, arg, "-Map=")) {
linker_map_file = arg["-Map=".len..];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handles -Map=file which is enough for me. Should -Map file be handled as well?

Comment on lines 1186 to 1187
options.symbol_wrap_set.count() > 0 or
options.linker_map_file != null)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what I'm actually doing here and whether I should do this.

Copy link
Member

@kubkon kubkon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this flag in an ELF linker? Additionally, before we consider this for merging, we need a test in test/link/elf.zig with llvm=true and lld=true. Once we move away from lld as the default linker, this will help in narrowing down the missing functionality.

@jiridanek jiridanek requested a review from kubkon January 4, 2024 17:22
@jiridanek
Copy link
Author

@kubkon I could not figure out how to check the .map file content from inside of the test. More importantly, i haven't figured out how to run the test I just wrote (or this test and the least amount of other tests) on my machine

% stage4/bin/zig test ../test/tests.zig --test-filter  testMapFlag
All 0 tests passed.
stage4/bin/zig test ../test/tests.zig --test-filter testMapFlag  4.76s user 1.58s system 100% cpu 6.333 total

Can you or anyone else please suggest how to do both correctly?

@andrewrk
Copy link
Member

andrewrk commented Jan 4, 2024

zig build test-link

You can pass --help to see more options (the help menu is augmented by the contents of build.zig scripts so it's different in different projects).

@andrewrk
Copy link
Member

andrewrk commented Jan 4, 2024

Please see #18356 (comment). @kubkon will be the final word on this, but I think it would be better to not even decide whether to add this functionality until some other things are done. Until then, if you need this feature you will need to use a different toolchain than zig cc. @kubkon please close this pull request if you agree.

@kubkon
Copy link
Member

kubkon commented Jan 5, 2024

I have to agree with @andrewrk here - this is a new feature request that while may look innocent and easy to implement with LLD in mind, it needs some careful consideration if ported to Zig's linker. Until we decide if we want to accept your proposal, I am closing this PR as not applicable.

@kubkon kubkon closed this Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zig cc: unsupported linker arg: -Map=skrouterd.map
3 participants