From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08370C47404 for ; Wed, 9 Oct 2019 06:54:39 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B6B7120B7C for ; Wed, 9 Oct 2019 06:54:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B6B7120B7C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.92.3) (envelope-from ) id 1iI5rQ-0008OG-Lj; Wed, 09 Oct 2019 02:54:12 -0400 Received: from pietrobattiston.it ([2001:4b98:dc0:41:216:3eff:feb1:1135] helo=jauntuale.pietrobattiston.it) by shelob.surriel.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) (envelope-from ) id 1iI5rN-0008O4-K7 for kernelnewbies@kernelnewbies.org; Wed, 09 Oct 2019 02:54:09 -0400 Received: from amalgama (unknown [IPv6:2a02:578:85b0:500:6544:6148:b2c5:4b58]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) (Authenticated sender: giovanni) by jauntuale.pietrobattiston.it (Postfix) with ESMTPSA id A3D20E5D9D for ; Wed, 9 Oct 2019 08:54:03 +0200 (CEST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by amalgama (Postfix) with ESMTP id 15D6D3C01F3 for ; Wed, 9 Oct 2019 08:54:03 +0200 (CEST) From: Giovanni Mascellani Subject: Re: Are there global constructors in the Linux kernel? To: kernelnewbies@kernelnewbies.org References: Openpgp: preference=signencrypt Autocrypt: addr=gio@debian.org; prefer-encrypt=mutual; keydata= mQINBEuFs48BEACkd+0TjHZ81/gFb0yEsiVhFJ5S3CaAQcFloMQ0PO/CPv4fMpOzL3tfko5Y KONBxZGE2NKsRz/z1V/84nzCWMxJdNV/c5hahuoCkCnxmoHkBsSgCzm6QgAc3c+QAZa71oRr rJxpH9TyvjMimq1ZNBEVY+vgKCWkkuBqil/UYwn3YVISwlHDSc2amKCA+dtb9EQv8oTJcr7C bACH1MqszW0kKNJrAvfkT2vnawhUB0bJeqLGUN8/F+2DDbHfqNPCEOMJY78/Set+m4uvgJyN btZ7fa6FSEsk22fT+KxyPVDbEktdECGz3oupYqh7pZSManqEIvDOzHKWgvjo2yCF3dzU/ykZ gOIk2AQ3DeSB6llHbHA2/2Ms+RH6eCb8Bx+GJ5Ta5DUNQh3DZyuWR/Doc3NsAoLsaOWHwH+P D9ctmP/1ZN5a7mRcj/IKPquTvxHfg81FmS2H84lv1RrgR36QzCMiJHWOgm9UePEk8xlVeG0r lZ9yNCikzMkxuIAhlmWEyeZ9RgKOnYKy/9OgELHWsRIsPIkORVkpwz/Rpar0gbxhOisBOVQW 2f7GvNtJFyeC+xSz4hVIFQAtS/JFXZ+R2/xuhxRY1cK7gQfELioFyXmb9/gPgPjwxjizttUr LFB7WH/lwPqA7znjh2si4CNBpgcPUgY8HPjhcFPqZvi/Gf6xSwARAQABtCRHaW92YW5uaSBN YXNjZWxsYW5pIDxnaW9AZGViaWFuLm9yZz6JAlcEEwEKA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+DiLyugFQke3H5lVZLdxO 0RM9GSSJDT6mitmZzQ7ItrWYZ/32+UFqCtlVuIbeg1jixf/k326gRZew71BpqywuVYqOHgIV /4iaaknnWsW7pjEqyClqW2T7IQclKpO8NI4qI63iGVdORCJYvK++k7y5CjYbiJOU4U5qfil3 M0rEVV1Kthf12KuXIPDyiHn8sgUP1dL0FIJhBw== Organization: Debian Message-ID: <7a3fa451-1f72-5c09-1a61-9e46f2237c3f@debian.org> Date: Wed, 9 Oct 2019 08:54:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============0105737434012901943==" Errors-To: kernelnewbies-bounces@kernelnewbies.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --===============0105737434012901943== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Zdf1glPUWLKbixsMmg55bcic1zOgTm6JG" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --Zdf1glPUWLKbixsMmg55bcic1zOgTm6JG Content-Type: multipart/mixed; boundary="vEqqKSSMOnz7kM9qc5QLnyNLVYPrjmiQa"; protected-headers="v1" From: Giovanni Mascellani To: kernelnewbies@kernelnewbies.org Message-ID: <7a3fa451-1f72-5c09-1a61-9e46f2237c3f@debian.org> Subject: Re: Are there global constructors in the Linux kernel? References: In-Reply-To: --vEqqKSSMOnz7kM9qc5QLnyNLVYPrjmiQa Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: quoted-printable Hi, [sending again after having replied just to the OP by mistake, sorry!] Il 09/10/19 05:44, CRISTIAN ANDRES VARGAS GONZALEZ ha scritto: > The gcc compiler searches for this function to run my program, but > before that happens, I can use the global constructors and write a code= > that runs before the main function, but in the case of writing a kernel= , > why do I need to run lines of code before the kernel is executed ?, I > understand that when writing a kernel there is no main function and tha= t > it is disabled to indicate it to the compiler. In the Linux kernel are > there global constructors? If so, what things are executed before > starting the kernel? I am not a Linux expert, but I think I know enough on this specific topic to give at least a partial answer: the global constructors feature depends on the initialization code in the C runtime environment, which depends on the operating system. In the case of the kernel, there is not another operating system around, so everything that must happen at initialization time must be done by the kernel itself, including setting up the stack, zeroing uninitialized data and calling whatever you want to be called. There cannot be any automatic way to do these things, because there is nobody except the kernel itself who can do that. This book has a nice and rather detailed write-up on what happens when Linux boots (at least on x86_64): https://0xax.gitbooks.io/linux-insides/ You will see that nothing is called "automatically" like for global constructors: everything is called explicitly and at the right moment. This is also necessary because early kernel initialization routines cannot assume that the system is in a consistent state, since their job is to bring it to be. Therefore you must control precisely what must happen when. Hope this helps! Giovanni. --=20 Giovanni Mascellani Postdoc researcher - Universit=C3=A9 Libre de Bruxelles --=20 Giovanni Mascellani Postdoc researcher - Universit=C3=A9 Libre de Bruxelles --vEqqKSSMOnz7kM9qc5QLnyNLVYPrjmiQa-- --Zdf1glPUWLKbixsMmg55bcic1zOgTm6JG Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEARYKAB0WIQSiBF6hBvCQNcghJEaNr8EMz954SQUCXZ2ECgAKCRCNr8EMz954 SeIqAQDEmLtncFI6MhBB/nx1bcKeRFtEt9N3ioH3jt7ueNL3+QD/epo8So9SNQnq y4EGGNEalZMSFBUJZc+LrsqVClP+zAQ= =4Htp -----END PGP SIGNATURE----- --Zdf1glPUWLKbixsMmg55bcic1zOgTm6JG-- --===============0105737434012901943== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies --===============0105737434012901943==--