-
Notifications
You must be signed in to change notification settings - Fork 11
Linker flags reorder #54
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,11 +86,15 @@ OPT_COMPILE_FLAGS = get_flag_group([ | |
|
|
||
| # Default link flags when no specific build type is selected. | ||
| DEFAULT_LINK_FLAGS = get_flag_group([ | ||
| "-Wl,-Bstatic", | ||
| "-lstdc++", | ||
| "-lgcc", | ||
| "-lgcc_eh", | ||
| "-Wl,-Bdynamic", | ||
|
Comment on lines
+89
to
+93
|
||
| "-lm", | ||
| "-ldl", | ||
| "-lrt", | ||
| "-static-libstdc++", | ||
| "-static-libgcc", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI-assisted review (Claude): [Important] This doesn't actually fix the link-order problem from issue #53 Issue #53 describes symbols from The flags here tell the linker: User objects (which reference The real solution is link groups. Replace this with: DEFAULT_LINK_FLAGS = get_flag_group([
"-static-libstdc++",
"-static-libgcc",
"-Wl,--start-group",
"-lm",
"-ldl",
"-lrt",
"-lgcc",
"-lgcc_eh",
"-Wl,--end-group",
])
|
||
| "-lc", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI-assisted review (Claude): [Suggestion]
|
||
| ]) | ||
|
|
||
| # Minimal set of warning flags to enable useful warnings without overwhelming the user. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI-assisted review (Claude):
[Important] Duplicate C++ runtime linkage — no
-nodefaultlibsin this toolchainThis toolchain uses
cxx_binary(g++) as the link driver for all link actions, and nowhere in the Linux toolchain do the flags include-nodefaultlibs. Without that flag, g++ automatically appends its own default runtime libraries at the end of every link command — including-lstdc++,-lgcc, and-lgcc_eh.The result is:
Static versions are linked early, dynamic versions are linked again at the end by the driver. That's dual runtime linkage: two copies of the C++ runtime with different linkage modes in the same binary, which can cause ODR violations, constructor double-invocation, or crashes.
The original
-static-libstdc++and-static-libgccare precisely the GCC mechanism for avoiding this: they instruct the driver to substitute its own default runtime with the static versions when it appends them at the end — no duplication. They're not a workaround; they're the intended interface.If the intent is to keep runtime libs static, the correct fix is to keep
-static-libstdc++/-static-libgccand address link order separately (see the second finding below).