linux 运行函数名,Linux启动第一集 之世界最有名的一个函数名

首先看一下内核中最有名气的一个函数(top1):

asmlinkage__visiblevoid __initstart_kernel(void)

第一个函数出来就有三个知识点,派头确实很大。

asmlinkage:

确保所有的参数都是栈传递。

#ifdef __cplusplus

#define CPP_ASMLINKAGE extern "C"

#else

#define CPP_ASMLINKAGE

#endif

#ifndef asmlinkage

#define asmlinkage CPP_ASMLINKAGE

#endif

include/linux/linkage.h

#ifdef CONFIG_X86_32

#define asmlinkage

CPP_ASMLINKAGE __attribute__((regparm(0)))

arch/x86/include/asm/linkage.h

__visible :

告诉优化器(optimizer)其它人会调用这个函数或者变量。

通过git可以查看此标识符引入的时候作者是怎么说的

git show

9a858dc7cebce01a7bb616bebb85087fa2b40871

+#if __GNUC_MINOR__ >= 6

+/*

+ * Tell the optimizer that something else uses this function or variable.

+ */

+#define __visible __attribute__((externally_visible))

+#endif

include/linux/compiler-gcc4.h

commit 9a858dc7cebce01a7bb616bebb85087fa2b40871

Author: Andi Kleen

Date:   Mon Sep 17 14:09:15 2012 -0700

compiler.h: add __visible

gcc 4.6+ has support for a externally_visible attribute that

prevents theoptimizer from optimizing unused symbols

away.  Add a __visible macro touse it with that compiler

version or later.

This is used (at least) by the "Link Time Optimization" patchset

__init

表明代码(text)和数据仅仅在初始化的时候需要。

1.定义

#define __init __section(.init.text) __cold notrace

#define __initdata __section(.init.data)

#define __initconst __constsection(.init.rodata)

#define __exitdata __section(.exit.data)

#define __exit_call __used __section(.exitcall.exit)

(include/linux/init.h)

#ifndef __cold

#define __cold __attribute__((__cold__))

#endif

(include/linux/compiler-gcc4.h)

#ifndef __section

# define __section(S) __attribute__ ((__section__(#S)))

#endif

...

#define notrace __attribute__((no_instrument_function))

(include/linux/compiler.h)

2.init*段都在一块连续的内存中

8d3e64591dd29e1a67e0a38e16b57bdc.png

(arch/x86/kernel/vmlinux.lds.S)

3. 她们都将被释放(释放的函数从kernel_init进入)

void free_initmem(void)

{

free_init_pages("unused kernel",

(unsigned long)(&__init_begin),

(unsigned long)(&__init_end));

}

(arch/x86/mm/init.c)

---The End---

文章与封面台词无关:)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值