From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x933.google.com (mail-ua1-x933.google.com [IPv6:2607:f8b0:4864:20::933]) by sourceware.org (Postfix) with ESMTPS id 986903958C22 for ; Thu, 29 Apr 2021 13:58:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 986903958C22 Received: by mail-ua1-x933.google.com with SMTP id x22so2684488uav.8 for ; Thu, 29 Apr 2021 06:58:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Mbx1hYo4+ACf2nEKlxgz/9R69sy9VB25Sc4Z8VakdQg=; b=RRiDxpsYb4FN3bakdsCQb6j4gtjRvIF2qzYZmMQx65ug7KKTHdXOgCFtQ8udYqkN/h jll9sB6bPLA+rEApxQJv3uH4lLjy/sgJHBb/VFuGYqCOiph8Mudj/LHQ78lMbSxzR/p2 XgT6vCyXuvyKOCxTp4WSwtY4b1b9YxZ+ptttWtIg2XY1im1zHqmhAsZxclaYdP19m8OP 0JHhYvSg/SNUBeQ/X9fdPxGwEWWxsER22RGlXl1CzwRozq/d4O3KQn799DYieltLpJSu jnMYBDDQJydpZdkUbSjbQrGSxIOskvSUHs75FMrvVqzM1UkTYLrMKhfLNBG6mrrmEjAJ 7BBA== X-Gm-Message-State: AOAM531HpVrP4p219Xyi6Nu/i6TS+91pdBenHl9WNZWmdMfnWiSULhQB 3dAZ3x0Bc9gdYll495GdWgbEkIfZj5su0IUYKNC7tIvu X-Google-Smtp-Source: ABdhPJzZZKSkdi1Ms1PcaJ4hbS6a0TDpKCFRAU1LCNCm/4bWQp294yCaHEVPJQZQYHYsCECKmOBWiUui8sermBWwdac= X-Received: by 2002:ab0:5f8d:: with SMTP id b13mr4178454uaj.4.1619704738905; Thu, 29 Apr 2021 06:58:58 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Peng Yu Date: Thu, 29 Apr 2021 08:58:47 -0500 Message-ID: Subject: minimal loader program in C To: libc-help Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-help@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-help mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Apr 2021 13:59:00 -0000 I see the following system calls are used when a program is run. I'd like to understand how this process is done in detail. Is there a minimal loader C program that just covers the basics of loading this simple program? $ cat main.c int main() { return 0; } $ gcc main.c $ strace ./a.out execve("./a.out", ["./a.out"], 0x7ffe586d5e60 /* 50 vars */) = 0 brk(NULL) = 0x562f27c1c000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=116056, ...}) = 0 mmap(NULL, 116056, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f71ab750000 close(3) = 0 openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@n\2\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=1839792, ...}) = 0 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f71ab74e000 mmap(NULL, 1852680, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f71ab589000 mprotect(0x7f71ab5ae000, 1662976, PROT_NONE) = 0 mmap(0x7f71ab5ae000, 1355776, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x25000) = 0x7f71ab5ae000 mmap(0x7f71ab6f9000, 303104, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x170000) = 0x7f71ab6f9000 mmap(0x7f71ab744000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1ba000) = 0x7f71ab744000 mmap(0x7f71ab74a000, 13576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f71ab74a000 close(3) = 0 arch_prctl(ARCH_SET_FS, 0x7f71ab74f540) = 0 mprotect(0x7f71ab744000, 12288, PROT_READ) = 0 mprotect(0x562f2789d000, 4096, PROT_READ) = 0 mprotect(0x7f71ab797000, 4096, PROT_READ) = 0 munmap(0x7f71ab750000, 116056) = 0 exit_group(0) = ? +++ exited with 0 +++ -- Regards, Peng