-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
Static on macosx #4332
Draft
Smilex
wants to merge
3
commits into
odin-lang:master
Choose a base branch
from
Smilex:static_on_macosx
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Static on macosx #4332
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -571,10 +571,6 @@ gb_internal i32 linker_stage(LinkerData *gen) { | |||||
link_settings = gb_string_append_fmt(link_settings, "-nostdlib "); | ||||||
} | ||||||
|
||||||
if (build_context.build_mode == BuildMode_StaticLibrary) { | ||||||
compiler_error("TODO(bill): -build-mode:static on non-windows targets"); | ||||||
} | ||||||
|
||||||
// NOTE(dweiler): We use clang as a frontend for the linker as there are | ||||||
// other runtime and compiler support libraries that need to be linked in | ||||||
// very specific orders such as libgcc_s, ld-linux-so, unwind, etc. | ||||||
|
@@ -631,7 +627,7 @@ gb_internal i32 linker_stage(LinkerData *gen) { | |||||
link_settings = gb_string_append_fmt(link_settings, "-mmacosx-version-min=%.*s ", LIT(build_context.minimum_os_version_string)); | ||||||
} | ||||||
|
||||||
if (build_context.build_mode != BuildMode_DynamicLibrary) { | ||||||
if (build_context.build_mode != BuildMode_DynamicLibrary && build_context.build_mode != BuildMode_StaticLibrary) { | ||||||
// This points the linker to where the entry point is | ||||||
link_settings = gb_string_appendc(link_settings, "-e _main "); | ||||||
} | ||||||
|
@@ -657,39 +653,56 @@ gb_internal i32 linker_stage(LinkerData *gen) { | |||||
platform_lib_str = gb_string_appendc(platform_lib_str, "-lc "); | ||||||
} | ||||||
} | ||||||
|
||||||
|
||||||
gbString link_command_line = gb_string_make(heap_allocator(), clang_path); | ||||||
defer (gb_string_free(link_command_line)); | ||||||
|
||||||
link_command_line = gb_string_appendc(link_command_line, " -Wno-unused-command-line-argument "); | ||||||
link_command_line = gb_string_appendc(link_command_line, object_files); | ||||||
link_command_line = gb_string_append_fmt(link_command_line, " -o \"%.*s\" ", LIT(output_filename)); | ||||||
link_command_line = gb_string_append_fmt(link_command_line, " %s ", platform_lib_str); | ||||||
link_command_line = gb_string_append_fmt(link_command_line, " %s ", lib_str); | ||||||
link_command_line = gb_string_append_fmt(link_command_line, " %.*s ", LIT(build_context.link_flags)); | ||||||
link_command_line = gb_string_append_fmt(link_command_line, " %.*s ", LIT(build_context.extra_linker_flags)); | ||||||
link_command_line = gb_string_append_fmt(link_command_line, " %s ", link_settings); | ||||||
|
||||||
if (build_context.use_lld) { | ||||||
link_command_line = gb_string_append_fmt(link_command_line, " -fuse-ld=lld"); | ||||||
result = system_exec_command_line_app("lld-link", link_command_line); | ||||||
if (build_context.build_mode == BuildMode_StaticLibrary) { | ||||||
if (is_osx) { | ||||||
gbString static_link_command_line = gb_string_make(heap_allocator(), "libtool"); | ||||||
defer (gb_string_free(static_link_command_line)); | ||||||
static_link_command_line = gb_string_append_fmt(static_link_command_line, " -o \"%.*s\" ", LIT(output_filename)); | ||||||
static_link_command_line = gb_string_appendc(static_link_command_line, " -static "); | ||||||
static_link_command_line = gb_string_appendc(static_link_command_line, object_files); | ||||||
return system_exec_command_line_app("libtool", static_link_command_line); | ||||||
} else { | ||||||
compiler_error("-build-mode:static on Linux and similar targets"); | ||||||
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.
Suggested change
|
||||||
} | ||||||
} else { | ||||||
result = system_exec_command_line_app("ld-link", link_command_line); | ||||||
} | ||||||
|
||||||
if (result) { | ||||||
return result; | ||||||
} | ||||||
|
||||||
if (is_osx && build_context.ODIN_DEBUG) { | ||||||
// NOTE: macOS links DWARF symbols dynamically. Dsymutil will map the stubs in the exe | ||||||
// to the symbols in the object file | ||||||
result = system_exec_command_line_app("dsymutil", "dsymutil %.*s", LIT(output_filename)); | ||||||
gbString link_command_line = gb_string_make(heap_allocator(), clang_path); | ||||||
defer (gb_string_free(link_command_line)); | ||||||
|
||||||
link_command_line = gb_string_appendc(link_command_line, " -Wno-unused-command-line-argument "); | ||||||
link_command_line = gb_string_append_fmt(link_command_line, " -o \"%.*s\" ", LIT(output_filename)); | ||||||
|
||||||
link_command_line = gb_string_appendc(link_command_line, object_files); | ||||||
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. why did you move the object files from before the -o to after it? |
||||||
link_command_line = gb_string_append_fmt(link_command_line, " %s ", platform_lib_str); | ||||||
link_command_line = gb_string_append_fmt(link_command_line, " %s ", lib_str); | ||||||
link_command_line = gb_string_append_fmt(link_command_line, " %.*s ", LIT(build_context.link_flags)); | ||||||
link_command_line = gb_string_append_fmt(link_command_line, " %.*s ", LIT(build_context.extra_linker_flags)); | ||||||
link_command_line = gb_string_append_fmt(link_command_line, " %s ", link_settings); | ||||||
|
||||||
if (build_context.use_lld) { | ||||||
link_command_line = gb_string_append_fmt(link_command_line, " -fuse-ld=lld"); | ||||||
result = system_exec_command_line_app("lld-link", link_command_line); | ||||||
} else { | ||||||
result = system_exec_command_line_app("ld-link", link_command_line); | ||||||
} | ||||||
|
||||||
if (result) { | ||||||
return result; | ||||||
} | ||||||
|
||||||
if (is_osx && build_context.ODIN_DEBUG) { | ||||||
// NOTE: macOS links DWARF symbols dynamically. Dsymutil will map the stubs in the exe | ||||||
// to the symbols in the object file | ||||||
result = system_exec_command_line_app("dsymutil", "dsymutil %.*s", LIT(output_filename)); | ||||||
|
||||||
if (result) { | ||||||
return result; | ||||||
} | ||||||
} | ||||||
|
||||||
} | ||||||
|
||||||
} | ||||||
} | ||||||
|
||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This does not look needed?
link_settings
isn't used when you do a static library from what I can tell.