在windows上安装或执行程序遇到的runtime是什么?

电子说

1.2w人已加入

描述

‍‍什么是runtime

在windows上安装或执行程序,都有机会遇到词汇——runtime。

CRT(C runtime library)

Microsoft Access 2016 Runtime

microsoft visual c++ runtime library

C Runtime

Visual C++ 2008 Runtime

.NET Common Language Runtime

runtime究竟是什么,首先runtime在英文里是合成单词,无论是英文还是中文都容易在文字层面被误解,中文直译“运行时”,中文的断句容易引起歧义,究竟是“运行、时”还是“运行时”傻傻分不清。

为了准确描述runtime的实际意思,我认为runtime换成execution environment理解起来更容易:即位应用程序的执行准备运行环境。

运行时库是在编译时使用的特殊库,用于在计算机程序的执行中实现内置于编程语言中的功能,包括:输入、输出、内存管理。

crt0

比如C语言需要的最小runtime叫做crt0(C runtime)。“crt”代表 “c runtime”,“0”代表“最基本、最开始”。crt0应该包含如下7个步骤。异常向量配置

_start函数和stack初始化

cache 初始化

清除BSS

构造函数和析构函数处理

C初始化功能

调用main入口这个crt0的结构看起来是不是很熟悉?没错,在u-boot源码启动代码看到类似结构。

.text.globl _start_start: # _start is the entry point known to the linker xor %ebp, %ebp # effectively RBP := 0, mark the end of stack frames mov (%rsp), %edi # get argc from the stack (implicitly zero-extended to 64-bit) lea 8(%rsp), %rsi # take the address of argv from the stack lea 16(%rsp,%rdi,8), %rdx # take the address of envp from the stack xor %eax, %eax # per ABI and compatibility with icc call main # %edi, %rsi, %rdx are the three args (of which first two are C standard) to main mov %eax, %edi # transfer the return of main to the first argument of _exit xor %eax, %eax # per ABI and compatibility with icc call _exit # terminate the program

crt0.S编译生成crt0.o,今后gcc编译的所有应用程序前都加上这段内容,既然有crt0,那么再发挥想象力,是不是还会有crt1什么的呢,全盘搜索看到若干crt前缀的*.o文件,这些crt*.o文件合并起来被称做 “runtime library”

运行时库和标准库区别

运行时库(runtime library)与标准库(standard library)不是一个东西。

标准库和运行库之间有一个非常重要的区别。尽管标准库定义了程序员可以使用的功能,但不是编程语言的规范的一部分,至少在C语言中不是,运行时库却时程序运行所必需的部分。

举个例子,printf()是C标准库的一部分,程序的启动是在运行时库实现的,启动过程对程序员不可见,因此,你编写的程序可以不使用标准库,但始终需要运行时库,否则无法运行。老实说,在操作系统上编写不使用标准库的应用程序几乎无实际意义,那样的程序没有访问外设的方法、屏幕上不会输出令人印象深刻的结果。在裸机上情况就不一样了,访问外设不需要系统调用,没有系统的权限隔离,外设的寄存器也有读写权限。

简单编写一个只有main

int main(int argc, char **argv){ return 0;}

编译后看看符号表:gcc a.c

readelf -s a.out很多不知那来的函数符号都来源与crt*.o,如register_tm_clones源于crtbegin.o;__data_start、__libc_start_main源于crt1.o

31: 0 FILE LOCAL DEFAULT ABS crtstuff.c32: 0 FUNC LOCAL DEFAULT 13 deregister_tm_clones33: 0 FUNC

LOCAL DEFAULT 13 register_tm_clones34: 0 FUNC

LOCAL DEFAULT 13 __do_global_dtors_aux35: 1 OBJECT LOCAL DEFAULT 24 completed.732536: 0 OBJECT

LOCAL DEFAULT 19 __do_global_dtors_aux_fin37: 0 FUNC LOCAL DEFAULT 13 frame_dummy38: 0 OBJECT

LOCAL DEFAULT 18 __frame_dummy_init_array_39: 0 FILE LOCAL DEFAULT ABS a.c40: 0 FILE

LOCAL DEFAULT ABS crtstuff.c41: 0 OBJECT LOCAL DEFAULT 17 __FRAME_END__42: 0 FILE

LOCAL DEFAULT ABS 43: 0 NOTYPE LOCAL DEFAULT 18 __init_array_end44: 0 OBJECT

LOCAL DEFAULT 20 _DYNAMIC45: 0 NOTYPE LOCAL DEFAULT 18 __init_array_start46: 0 NOTYPE

LOCAL DEFAULT 16 __GNU_EH_FRAME_HDR47: 0 OBJECT LOCAL DEFAULT 22 _GLOBAL_OFFSET_TABLE_48: 0 FUNC

LOCALDEFAULT 10 _init49: 1 FUNC GLOBAL DEFAULT 13 __libc_csu_fini50: 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab51: 0 NOTYPE WEAK DEFAULT 23 data_start52: 0 NOTYPE GLOBAL DEFAULT 23 _edata53: 0 FUNC GLOBAL HIDDEN 14 _fini54: 0 FUNC GLOBAL DEFAULT UND

__libc_start_main@@GLIBC_55: 0 NOTYPE GLOBAL DEFAULT 23 __data_start56: 0 NOTYPE WEAK DEFAULT UND

__gmon_start__57: 0 OBJECT GLOBAL HIDDEN 23 __dso_handle58: 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_used59: 93 FUNC GLOBAL DEFAULT 13 __libc_csu_init60: 0 NOTYPE GLOBAL DEFAULT 24 _end61: 43 FUNC GLOBAL DEFAULT 13 _start62: 0 NOTYPE GLOBAL DEFAULT 24 __bss_start63: 18 FUNC GLOBAL DEFAULT 13 main64: 0 OBJECT GLOBAL HIDDEN 23 __TMC_END__65: 0 NOTYPE WEAK DEFAULT UND

_ITM_registerTMCloneTable66: 0 FUNC WEAK DEFAULT UND __cxa_finalize@@GLIBC_2.2

原文标题:runtime是什么

文章出处:【微信公众号:嵌入式ARM】欢迎添加关注!文章转载请注明出处。

责任编辑:haq

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分