Skip to content

Opting out of libc on Apple Silicon #5

Description

@saagarjha

Embedded platforms don't do static. However, if you're still curious here's how you can convince Xcode to make those files:

diff --git a/AsMain/main.s b/AsMain/main.s
index 953236a..61760cd 100644
--- a/AsMain/main.s
+++ b/AsMain/main.s
@@ -6,12 +6,11 @@
 // X16 - Mach function number
 //
 
-.global _main	            // Provide program starting address to linker
+.global start	            // Provide program starting address to linker
 .align 2
-
 // Setup the parameters to print hello world
 // and then call Linux to do it.
-_main: mov	X0, #1	    // 1 = StdOut
+start: mov	X0, #1	    // 1 = StdOut
     adr	X1, helloworld // string to print
 	mov	X2, #13	    // length of our string
 	mov	X16, #4	    // linux write system call
diff --git a/MacAs.xcodeproj/project.pbxproj b/MacAs.xcodeproj/project.pbxproj
index 11b501e..f95d6bd 100644
--- a/MacAs.xcodeproj/project.pbxproj
+++ b/MacAs.xcodeproj/project.pbxproj
@@ -318,6 +318,8 @@
 			isa = XCBuildConfiguration;
 			buildSettings = {
 				CODE_SIGN_STYLE = Automatic;
+				LINK_WITH_STANDARD_LIBRARIES = NO;
+				OTHER_LDFLAGS = "-static";
 				PRODUCT_NAME = "$(TARGET_NAME)";
 			};
 			name = Debug;
@@ -326,6 +328,8 @@
 			isa = XCBuildConfiguration;
 			buildSettings = {
 				CODE_SIGN_STYLE = Automatic;
+				LINK_WITH_STANDARD_LIBRARIES = NO;
+				OTHER_LDFLAGS = "-static";
 				PRODUCT_NAME = "$(TARGET_NAME)";
 			};
 			name = Release;

Screen Shot 2020-07-04 at 19 50 03

If you put an underscore in front of main in both places and give up on static linking:

Screen Shot 2020-07-04 at 19 51 31

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions