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.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, 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 8C29EC47404 for ; Wed, 9 Oct 2019 08:55:02 +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 EBBCC206B6 for ; Wed, 9 Oct 2019 08:55:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=swemel.ru header.i=@swemel.ru header.b="c6sOf6lA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EBBCC206B6 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=swemel.ru 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 1iI7jx-00037C-1u; Wed, 09 Oct 2019 04:54:37 -0400 Received: from mail.swemel.ru ([79.135.238.163]) by shelob.surriel.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.3) (envelope-from ) id 1iI7jt-000375-B3 for kernelnewbies@kernelnewbies.org; Wed, 09 Oct 2019 04:54:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=swemel.ru; s=17022016; h=Subject:Content-Transfer-Encoding:Content-Type:In-Reply-To: References:To:MIME-Version:From:Date:Message-ID; bh=DNOVOpd7Viim3sKbfNtl6Wzx6GWaUDh2X4ivz7wz1k4=; b=c6sOf6lAvxDBYSd0YDLJeV2ZD4 HTIj+tTAEVWxED45QvA0mB4OPos+vSQ54qnjh/dx+jLocBtYJTaZEU7uY/u9rcUbFBsLZRnRswgw+ krgaGj4V8de5vUFgXjoVYzlpWwls672yMgq+Ki7dh3ZhnDzItzT2/F8Kglaj85hR+TPA=; Received: from [10.1.20.204] (helo=mail.swemel.grp) by mail.swemel.ru with esmtp (Exim 4.86_2) (envelope-from ) id 1iI7jm-0008Qh-Q4; Wed, 09 Oct 2019 11:54:28 +0300 Received: from [10.1.200.208] ([10.1.200.208]) by mail.swemel.grp with Microsoft SMTPSVC(6.0.3790.4675); Wed, 9 Oct 2019 11:54:26 +0300 Message-ID: <5D9DA042.2090205@swemel.ru> Date: Wed, 09 Oct 2019 11:54:26 +0300 From: Konstantin Andreev Organization: Swemel JSC User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: CRISTIAN ANDRES VARGAS GONZALEZ , kernelnewbies@kernelnewbies.org References: In-Reply-To: X-OriginalArrivalTime: 09 Oct 2019 08:54:26.0658 (UTC) FILETIME=[2789B420:01D57E7F] X-SA-Exim-Connect-IP: 10.1.20.204 X-SA-Exim-Mail-From: andreev@swemel.ru Subject: Re: Are there global constructors in the Linux kernel? X-SA-Exim-Version: 4.2.1 (built Sun, 16 Aug 2015 09:47:37 +0000) X-SA-Exim-Scanned: No (on mail.swemel.ru); Unknown failure 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: kernelnewbies-bounces@kernelnewbies.org Hi, Cristian. There are, a kinda of ... kernel/taskstats.c: | late_initcall(taskstats_init); kernel/rcu/update.c: | early_initcall(check_cpu_stall_init); There is a whole set of macros STAGE_initcall() in include/linux/init.h Arguments to these macros invokations are accounted and called by kernel initialization code at strictly defined stages of initialization. See https://0xax.gitbooks.io/linux-insides/content/Concepts/linux-cpu-3.html The only thing that is run before kernel is platform-specific boot loaders, maybe under hypervisor control. Compiler has no power to insert something in between. Regards, Konstantin. CRISTIAN ANDRES VARGAS GONZALEZ, 09 Oct 2019 06:44 MSK: > > Good day > > I have been doing a little kernel following some repositories of GitHub, videos and wikis, and I have found a topic that leaves me with doubts, the theme is the global constructors. > > Suppose I write a program in c, for the user space, for my code to run I must have the main function > int main() { /*Code*/} > > 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 that 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? > att: cristian vargas. _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies