Skip to content
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

zig cc: unsupported linker arg: -Map=skrouterd.map #18356

Open
jiridanek opened this issue Dec 23, 2023 · 4 comments
Open

zig cc: unsupported linker arg: -Map=skrouterd.map #18356

jiridanek opened this issue Dec 23, 2023 · 4 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. linking proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@jiridanek
Copy link

jiridanek commented Dec 23, 2023

Zig Version

0.11.0

Steps to Reproduce and Observed Behavior

Here's a fragment of my actual command (obtained from VERBOSE=1 make)

$ clang -O2 -g -DNDEBUG -flto=thin -Wl,--export-dynamic -rdynamic  -Xlinker -Map=skrouterd.map
/usr/bin/ld: /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../lib64/crt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Clang does not complain about the -Map option (and if all parameters were given, the linking would succeed)

When I run the same compilation with zig cc instead of clang, I get an error from command line argument parser

$ zig cc -O2 -g -DNDEBUG -flto=thin -Wl,--export-dynamic -rdynamic  -Xlinker -Map=skrouterd.map
error: unsupported linker arg: -Map=skrouterd.map

Expected Behavior

Please support the -Map= linker argument. I can try looking into this myself if given some initial pointers on what needs to be done. Thanks.

@jiridanek jiridanek added the bug Observed behavior contradicts documented or intended behavior label Dec 23, 2023
@jiridanek
Copy link
Author

jiridanek commented Dec 23, 2023

Looks like the first step towards implementing this would be here

zig/src/main.zig

Lines 2397 to 2402 in 1b0e913

} else if (mem.eql(u8, arg, "--version")) {
try std.io.getStdOut().writeAll("zig ld " ++ build_options.version ++ "\n");
process.exit(0);
} else {
fatal("unsupported linker arg: {s}", .{arg});
}

Looking at the previous issues of this kind, it looks to me that fix should be similar to how wrap is handled

@jiridanek jiridanek changed the title Support linker map files in zig cc zig cc: unsupported linker arg: -Map=skrouterd.map Dec 23, 2023
@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. linking proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. and removed bug Observed behavior contradicts documented or intended behavior labels Jan 4, 2024
@andrewrk andrewrk added this to the 0.15.0 milestone Jan 4, 2024
@andrewrk
Copy link
Member

andrewrk commented Jan 4, 2024

I'm marking this as a proposal to indicate that we might not decide to support it after all. Diagnostic and debugging features are important, but it is an area we may choose to diverge from other tools in order to unlock a different set of design requirements.

I think it would be better to decide what to do about this feature request until after #17749 is done.

@jiridanek
Copy link
Author

jiridanek commented Jan 5, 2024

After having a second look at the project I wanted to cross-compile, I realized that indeed the linker map is written out only for human inspection and the software itself does not touch it afterwards. It does not even try to install the map file to /usr/share or something like that... Previously I somehow got stuck on the idea that it loads the map file at runtime and parses out something out of it, which simply is not the case. (It does open and read /proc/self/map, but that is something completely different.)

So, I used cmake to check for -Map availability and skip it if not supported. Problem solved.

include(CheckLinkerFlag)
check_linker_flag(C "LINKER:-Map=skrouterd.map" linker_map_supported)

add_executable(skrouterd ${router_SOURCES})
target_include_directories(skrouterd PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(skrouterd PRIVATE skupper-router)
if (linker_map_supported)
    target_link_options(skrouterd PUBLIC LINKER:-Map=skrouterd.map)
else ()
    message(WARNING "Linker map generation not supported, skrouterd.map will not be written out")
endif ()

@andrewrk
Copy link
Member

andrewrk commented Jan 5, 2024

Nice work finding a workaround - thanks for sharing it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. linking proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants