public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
From: Johnny Richard <johnny@johnnyrichard.com>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Johnny Richard <johnny@johnnyrichard.com>
Subject: [PATCH olang v1 1/3] codegen: link olang binary with libc by default
Date: Thu, 17 Oct 2024 02:19:58 +0200	[thread overview]
Message-ID: <20241017002102.454851-2-johnny@johnnyrichard.com> (raw)
In-Reply-To: <20241017002102.454851-1-johnny@johnnyrichard.com>

Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
---
 src/codegen_linux_x86_64.c | 19 ++-----------------
 src/main.c                 |  2 +-
 2 files changed, 3 insertions(+), 18 deletions(-)

diff --git a/src/codegen_linux_x86_64.c b/src/codegen_linux_x86_64.c
index 83d1d2c..6d38b53 100644
--- a/src/codegen_linux_x86_64.c
+++ b/src/codegen_linux_x86_64.c
@@ -61,9 +61,6 @@ static int x86_call_args[X86_CALL_ARG_SIZE] = { REG_DEST_IDX, REG_SRC_IDX,
                                                 REG_DATA,     REG_R10,
                                                 REG_R8,       REG_R9 };
 
-static void
-codegen_linux_x86_64_emit_start_entrypoint(codegen_x86_64_t *codegen);
-
 static void
 codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen,
                                    ast_fn_definition_t *fn);
@@ -103,7 +100,7 @@ codegen_linux_x86_64_emit_translation_unit(codegen_x86_64_t *codegen,
                                            ast_node_t *node)
 {
     codegen->label_index = 0;
-    codegen_linux_x86_64_emit_start_entrypoint(codegen);
+    fprintf(codegen->out, ".text\n");
 
     assert(node->kind == AST_NODE_TRANSLATION_UNIT);
     ast_translation_unit_t translation_unit = node->as_translation_unit;
@@ -130,19 +127,6 @@ codegen_linux_x86_64_emit_translation_unit(codegen_x86_64_t *codegen,
     assert(main_found && "main function is required.");
 }
 
-static void
-codegen_linux_x86_64_emit_start_entrypoint(codegen_x86_64_t *codegen)
-{
-    fprintf(codegen->out, ".text\n");
-    fprintf(codegen->out, ".globl _start\n\n");
-
-    fprintf(codegen->out, "_start:\n");
-    fprintf(codegen->out, "    call main\n");
-    fprintf(codegen->out, "    mov %%eax, %%edi\n");
-    fprintf(codegen->out, "    mov $%d, %%eax\n", SYS_exit);
-    fprintf(codegen->out, "    syscall\n");
-}
-
 static size_t
 codegen_linux_x86_64_get_next_label(codegen_x86_64_t *codegen)
 {
@@ -956,6 +940,7 @@ static void
 codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen,
                                    ast_fn_definition_t *fn_def)
 {
+    fprintf(codegen->out, ".globl " SV_FMT "\n", SV_ARG(fn_def->id));
     codegen->base_offset = 0;
 
     ast_node_t *block_node = fn_def->block;
diff --git a/src/main.c b/src/main.c
index 2b02564..c68fd48 100644
--- a/src/main.c
+++ b/src/main.c
@@ -185,7 +185,7 @@ handle_codegen_linux(cli_opts_t *opts)
     }
 
     sprintf(command,
-            "%s/bin/ld " SV_FMT ".o -o " SV_FMT "",
+            "%s/bin/cc " SV_FMT ".o -o " SV_FMT,
             opts->sysroot,
             SV_ARG(opts->output_bin),
             SV_ARG(opts->output_bin));
-- 
2.46.0


  parent reply	other threads:[~2024-10-16 22:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-17  0:19 [PATCH olang v1 0/3] cli: enable object file binary compilation Johnny Richard
2024-10-16 22:25 ` Carlos Maniero
2024-10-17  0:19 ` Johnny Richard [this message]
2024-10-17  0:19 ` [PATCH olang v1 2/3] cli: add option -c to compile without linking Johnny Richard
2024-10-17  0:20 ` [PATCH olang v1 3/3] codegen: remove linux from codegen namespace Johnny Richard
2024-10-16 22:22   ` [olang/patches/.build.yml] build success builds.sr.ht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241017002102.454851-2-johnny@johnnyrichard.com \
    --to=johnny@johnnyrichard.com \
    --cc=~johnnyrichard/olang-devel@lists.sr.ht \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.johnnyrichard.com/olang.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox