From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id SJlGD3g8EGeeaQAA62LTzQ:P1 (envelope-from ) for ; Thu, 17 Oct 2024 00:21:44 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id SJlGD3g8EGeeaQAA62LTzQ (envelope-from ) for ; Thu, 17 Oct 2024 00:21:44 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; none Received: from mail-a.sr.ht (mail-a.sr.ht [46.23.81.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 31CDC1E93C for ; Thu, 17 Oct 2024 00:21:43 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=qile2bquzxrcCSSTsa6VvUjnYA0h+hLLYCb0MmOW9qw=; c=simple/simple; d=lists.sr.ht; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1729117303; v=1; b=lcE5XockicRtbfAy0+3sadQQxOxrJayDuTwbPD6GM21HHnvWx/CrlyBRtWT92ua5+n/JnOPD P8aYwUy3tLpTB6WETKWVelkKfdmCu75N7FyjKtQWBJp0e3Zc8U8r79ybrbWse4V9k2VjkP7fHRd dqRtBvJsU/lExwc6eFMeQ73aCacC06xVFnNqa1kBRrDZN3SZnxDctfUENXnh+44DhJ5kY8mmVk0 Zb5cOTxUlQz7mC59IwoQnGab8xLT43B/RIMc32gBRbDxRnPeXtvyIsAzXx7jkuNDx+vAGRH/zKt CNn+MgZspRZIHck9e8Hvs4upaI25Ekm27uAxjmmZEl2iQ== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 1DDD6202C9 for ; Wed, 16 Oct 2024 22:21:43 +0000 (UTC) Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) by mail-a.sr.ht (Postfix) with ESMTPS id 3A11D2013F for <~johnnyrichard/olang-devel@lists.sr.ht>; Wed, 16 Oct 2024 22:21:42 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1729117302; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x8xAT3dZdN5vZLcsFdzhiZxeEDVP0crs19I9l/ubjTw=; b=eRXXAP//Kar8vhdNYymBq6XuDUBxQCtC1fxe1EQ8O3FPtWNvWs03HMq39W+oV8Pw4nI2KZ EoFybly1zvh37w5Q755S4NpRNl6oj8aYUKLZ+juA1dsmtHTrd737uMlWjNYAnIkZLHRBwr QLomUdmNvOguz4P8V84fAdFjvvsKbN71hfJwgDHQyCws9h2AfMddXj4NgQiOF3FU+K93I9 j2Db/T0tnrBe3LXMIJfU3Ko8zvMpxPB3oMGJRO5fmuha3exPOLVcPhWPJap50OqAx81Gv9 6Sin7PnLoYtzn+yHDX3SiVQRQDLKLiS8l1Zt/PIb5cCYXn9obKTqJ9j8yFSaKw== From: Johnny Richard To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Johnny Richard Subject: [PATCH olang v1 1/3] codegen: link olang binary with libc by default Date: Thu, 17 Oct 2024 02:19:58 +0200 Message-ID: <20241017002102.454851-2-johnny@johnnyrichard.com> In-Reply-To: <20241017002102.454851-1-johnny@johnnyrichard.com> References: <20241017002102.454851-1-johnny@johnnyrichard.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Sourcehut-Patchset-Status: UNKNOWN List-Unsubscribe: List-Subscribe: List-Archive: Archived-At: List-Post: List-ID: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel.lists.sr.ht> Sender: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel@lists.sr.ht> X-Migadu-Flow: FLOW_IN X-Migadu-Country: NL X-Migadu-Spam-Score: -4.00 X-Spam-Score: -4.00 X-Migadu-Queue-Id: 31CDC1E93C X-Migadu-Scanner: mx12.migadu.com X-TUID: 9uEb+T9vaJXz Signed-off-by: Johnny Richard --- 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