[go: up one dir, main page]

CN102750364A - Method, compiler and system for distributing memory address space for image files - Google Patents

Method, compiler and system for distributing memory address space for image files Download PDF

Info

Publication number
CN102750364A
CN102750364A CN2012101943456A CN201210194345A CN102750364A CN 102750364 A CN102750364 A CN 102750364A CN 2012101943456 A CN2012101943456 A CN 2012101943456A CN 201210194345 A CN201210194345 A CN 201210194345A CN 102750364 A CN102750364 A CN 102750364A
Authority
CN
China
Prior art keywords
source file
memory address
processed
current source
file
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN2012101943456A
Other languages
Chinese (zh)
Other versions
CN102750364B (en
Inventor
钟云德
周巍
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Henan Kunlun Technology Co ltd
XFusion Digital Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN201210194345.6A priority Critical patent/CN102750364B/en
Publication of CN102750364A publication Critical patent/CN102750364A/en
Application granted granted Critical
Publication of CN102750364B publication Critical patent/CN102750364B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

本发明实施例公开了一种为多镜像文件分配内存地址空间的方法、编译器和系统,涉及计算机技术领域,能够充分利用内存地址空间。该方法包括:根据前一个源文件的镜像文件所需的内存地址空间及前一个源文件的可用内存地址范围计算当前待处理源文件的可用内存地址范围;根据当前待处理源文件的可用内存地址范围生成所述当前待处理源文件的链接脚本,使生成的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址;使用生成的链接脚本对所述待处理源文件进行编译链接,生成待处理源文件的镜像文件。主要用于多镜像文件分配内存地址空间。

The embodiment of the invention discloses a method, a compiler and a system for allocating memory address space for multiple image files, relates to the technical field of computers, and can make full use of the memory address space. The method comprises: calculating the available memory address range of the current source file to be processed according to the memory address space required by the image file of the previous source file and the available memory address range of the previous source file; according to the available memory address range of the current source file to be processed The range generates the link script of the current source file to be processed, so that the initial memory address of the stored image file recorded in the generated link script is the initial address of the available memory address range of the current source file to be processed; The linking script compiles and links the source file to be processed to generate an image file of the source file to be processed. It is mainly used for multiple image files to allocate memory address space.

Description

为多镜像文件分配内存地址空间的方法、编译器和系统Method, compiler and system for allocating memory address space for multiple image files

技术领域 technical field

本发明涉及计算机技术领域,尤其涉及为多镜像文件分配内存地址空间的方法、编译器和系统。The invention relates to the field of computer technology, in particular to a method, a compiler and a system for allocating memory address spaces for multiple image files.

背景技术 Background technique

在编写源码时通常采用高级语言进行编写,如C语言、C++等,但是,计算机能够运行的只有机器语言,因此,需要对源码进行编译链接,生成能够被计算机运行的机器语言。源码经过编译器编译链接产生的目标文件称之为Image(镜像文件),Image由节区(section)组成,节区是编译器链接的一种属性,用于对全局符号(变量、函数)进行分组,实现符号存储地址指定。在编译链接过程中使用LSP(linker script链接脚本)规定如何把源文件内的节区放入Image内,并控制Image内各部分在内存地址空间内的布局。为了方便、有效的在现有的内存芯片上部署更多的业务软件,内存芯片地址空间资源的有效利用显得尤为重要。When writing the source code, it is usually written in a high-level language, such as C language, C++, etc. However, only the machine language can be run by the computer. Therefore, it is necessary to compile and link the source code to generate a machine language that can be run by the computer. The target file generated by the source code compiled and linked by the compiler is called Image (mirror file), and the Image is composed of sections. Grouping to realize symbol storage address specification. In the process of compiling and linking, LSP (linker script) is used to specify how to put the sections in the source file into the Image, and control the layout of each part in the Image in the memory address space. In order to deploy more business software on the existing memory chip conveniently and effectively, it is particularly important to effectively utilize memory chip address space resources.

现有技术中,在为多个业务软件分配内存地址空间时,为了避免不同Image使用的内存地址空间发生交叠,都是预先为各个Image分配内存地址空间,再对每个源文件进行编译链接使生成的Image使用预先被分配的内存地址空间。In the prior art, when allocating memory address spaces for multiple business software, in order to avoid overlapping of memory address spaces used by different images, memory address spaces are allocated for each image in advance, and then each source file is compiled and linked Make the generated Image use the pre-allocated memory address space.

上述分配内存地址空间资源的方法,预先为每个Image划分的内存地址空间通过用户经验给出,不能保证分配给每个Image的内存地址空间与该Image的大小相适应,容易出现分配给某个Image的内存地址空间不够或较多的情况。如果分配给某个Image的内存地址空间不够,则必须重新为每个Image分配内存地址空间,否则,内存地址空间不够的Image对应的业务无法实现,耗费巨大工作量;如果分配给某个Image的内存地址空间较多,虽然不重新为每个Image分配内存地址空间,也能够实现内存地址空间较多的Image对应的业务,但会导致内存地址碎片存在,造成内存地址空间的浪费。The above method of allocating memory address space resources, the pre-divided memory address space for each Image is given by user experience, it cannot be guaranteed that the memory address space allocated to each Image is suitable for the size of the Image, and it is easy to allocate to a certain image. Image memory address space is insufficient or more. If the memory address space allocated to an Image is not enough, the memory address space must be re-allocated for each Image, otherwise, the business corresponding to the Image with insufficient memory address space cannot be realized, which takes a huge amount of work; if the memory address space allocated to a certain Image There are many memory address spaces. Although the services corresponding to images with many memory address spaces can be implemented without re-allocating the memory address space for each Image, this will lead to memory address fragments and waste memory address space.

发明内容Contents of the invention

本发明的实施例提供一种为多镜像文件分配内存地址空间的方法、编译器和系统,能够充分利用内存地址空间。Embodiments of the present invention provide a method, a compiler and a system for allocating memory address space for multiple image files, which can make full use of the memory address space.

为达到上述目的,本发明的实施例采用如下技术方案:In order to achieve the above object, embodiments of the present invention adopt the following technical solutions:

一方面,一种为多镜像文件分配内存地址空间的方法,包括:In one aspect, a method for allocating memory address space for multiple image files, comprising:

根据前一个源文件的镜像文件所需的内存地址空间及前一个源文件的可用内存地址范围计算当前待处理源文件的可用内存地址范围;Calculate the available memory address range of the current source file to be processed according to the memory address space required by the image file of the previous source file and the available memory address range of the previous source file;

根据当前所述待处理源文件的可用内存地址范围生成所述当前待处理源文件的链接脚本,使生成的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址;Generate the link script of the current source file to be processed according to the available memory address range of the current source file to be processed, so that the initial memory address of the image file stored in the generated link script is the address of the current source file to be processed The starting address of the available memory address range;

使用生成的链接脚本对所述当前待处理源文件进行编译链接,生成所述当前待处理源文件的镜像文件。Compiling and linking the current source file to be processed by using the generated link script to generate an image file of the current source file to be processed.

进一步可选的,在所述根据前一个源文件的镜像文件所需的内存地址空间及前一个源文件的可用内存地址范围计算当前待处理源文件的可用内存地址范围之前,所述方法还包括:Further optionally, before calculating the available memory address range of the current source file to be processed according to the memory address space required by the image file of the previous source file and the available memory address range of the previous source file, the method further includes :

根据前一个源文件的镜像文件包含的各个节区的大小计算前一个源文件的镜像文件所需的内存地址空间。The memory address space required by the image file of the previous source file is calculated according to the size of each section contained in the image file of the previous source file.

进一步可选的,所述从前一个源文件的可用内存地址范围中去除前一个源文件的镜像文件所需的内存地址空间包括:Further optionally, the memory address space required for removing the image file of the previous source file from the available memory address range of the previous source file includes:

确定前一个源文件的可用内存地址范围的起始地址;Determine the start address of the available memory address range of the previous source file;

从所述起始地址开始,去除前一个源文件的镜像文件所需的内存地址空间。Starting from the starting address, the memory address space required by the image file of the previous source file is removed.

进一步可选的,所述根据当前待处理源文件的可用内存地址范围生成所述当前待处理源文件的链接脚本包括:Further optionally, the generating the link script of the current source file to be processed according to the available memory address range of the current source file to be processed includes:

将所述当前待处理源文件中各个节区的共享属性添加到所述当前待处理源文件中;adding the shared attributes of each section in the current source file to be processed to the current source file to be processed;

根据所述当前待处理源文件中各个节区的共享属性和所述当前可用内存地址范围生成所述当前待处理源文件的链接脚本;或者,Generate the link script of the current source file to be processed according to the shared attribute of each section in the current source file to be processed and the currently available memory address range; or,

根据当前可用内存地址范围修改预设链接脚本中记录的存放镜像文件的起始内存地址,得到所述当前待处理源文件的链接脚本。Modifying the initial memory address for storing the image file recorded in the preset link script according to the currently available memory address range to obtain the link script of the current source file to be processed.

进一步可选的,所述根据当前待处理源文件的可用内存地址范围生成所述当前待处理源文件的链接脚本包括:Further optionally, the generating the link script of the current source file to be processed according to the available memory address range of the current source file to be processed includes:

根据所述当前待处理源文件中每个节区的大小确定所述当前待处理源文件的链接脚本中记录的存放所述每个节区的起始内存地址。The initial memory address for storing each section recorded in the link script of the current source file to be processed is determined according to the size of each section in the current source file to be processed.

另一方面,一种编译器,包括:On the other hand, a compiler comprising:

第一计算单元,用于根据前一个源文件的镜像文件所需的内存地址空间及前一个源文件的可用内存地址范围计算当前待处理源文件的可用内存地址范围,将得到的所述当前待处理源文件的可用内存地址范围发送至生成单元;The first calculation unit is used to calculate the available memory address range of the current source file to be processed according to the memory address space required by the image file of the previous source file and the available memory address range of the previous source file, and obtain the current pending source file. The available memory address range of the processing source file is sent to the generation unit;

生成单元,用于接收所述第一计算单元发送的所述当前待处理源文件的可用内存地址范围,根据所述当前待处理源文件的可用内存地址范围生成所述当前待处理源文件的链接脚本,使生成的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址,将生成的所述当前待处理源文件的链接脚本发送至编译链接单元;A generation unit, configured to receive the available memory address range of the current source file to be processed sent by the first calculation unit, and generate a link of the current source file to be processed according to the available memory address range of the current source file to be processed The script makes the initial memory address of storing the image file recorded in the generated link script be the initial address of the available memory address range of the current source file to be processed, and sends the link script of the generated source file to be processed to compile the link unit;

编译链接单元,用于接收所述生成单元发送的所述当前待处理源文件的链接脚本,使用生成的链接脚本对所述当前待处理源文件进行编译链接,生成所述当前待处理源文件的镜像文件。A compiling and linking unit, configured to receive the link script of the current source file to be processed sent by the generating unit, use the generated link script to compile and link the current source file to be processed, and generate the link script of the current source file to be processed mirror file.

进一步可选的,还包括:Further optional, also include:

第二计算单元,用于根据前一个源文件的镜像文件包含的各个节区的大小计算前一个源文件的镜像文件所需的内存地址空间,将计算得到的前一个源文件的镜像文件所需的内存地址空间发送至所述第一计算单元;The second calculation unit is used to calculate the memory address space required by the image file of the previous source file according to the size of each section contained in the image file of the previous source file, and calculate the required memory address space of the image file of the previous source file. sending the memory address space of the first computing unit;

所述第一计算单元,还用于接收所述第二计算单元发送的前一个源文件的镜像文件所需的内存地址空间。The first computing unit is further configured to receive the memory address space required by the image file of the previous source file sent by the second computing unit.

进一步可选的,所述第一计算单元包括:Further optionally, the first calculation unit includes:

第一确定子单元,用于确定前一个源文件的可用内存地址范围的起始地址,并将确定的所述起始地址发送至去除子单元;The first determination subunit is configured to determine the start address of the available memory address range of the previous source file, and send the determined start address to the removal subunit;

去除子单元,用于接收所述确定子单元发送的所述起始地址,从所述起始地址开始,去除前一个源文件的镜像文件所需的内存地址空间。The removing subunit is configured to receive the starting address sent by the determining subunit, and start from the starting address to remove the memory address space required by the image file of the previous source file.

进一步可选的,所述生成单元包括:Further optionally, the generating unit includes:

添加子单元,用于将所述当前待处理源文件中各个节区的共享属性添加到所述当前待处理源文件中,将所述当前待处理源文件中各个节区的共享属性发送至第一生成子单元,或将所述当前待处理源文件中各个节区的共享属性发送至第二生成子单元;Adding a subunit for adding the shared attributes of each section in the current source file to be processed to the current source file to be processed, and sending the shared attributes of each section in the current source file to be processed to the first a generating subunit, or sending the shared attributes of each section in the current source file to be processed to a second generating subunit;

第一生成子单元,用于接收所述添加子单元发送的所述当前待处理源文件中各个节区的共享属性,根据所述当前待处理源文件中各个节区的共享属性和所述当前可用内存地址范围生成所述当前待处理源文件的链接脚本;或者,The first generation subunit is configured to receive the shared attribute of each section in the current source file to be processed sent by the adding subunit, and according to the shared attribute of each section in the current source file to be processed and the current A range of memory addresses is available to generate a linker script for said currently pending source file; or,

第二生成子单元,用于接收所述添加子单元发送的所述当前待处理源文件中各个节区的共享属性,根据当前可用内存地址范围修改预设链接脚本中记录的存放镜像文件的起始内存地址,得到所述当前待处理源文件的链接脚本。The second generation subunit is used to receive the shared attribute of each section in the current source file to be processed sent by the adding subunit, and modify the origin of storing the image file recorded in the preset link script according to the current available memory address range The initial memory address is obtained to obtain the link script of the current source file to be processed.

进一步可选的,所述生成单元包括:Further optionally, the generating unit includes:

第二确定子单元,用于根据所述当前待处理源文件中每个节区的大小确定所述当前待处理源文件的链接脚本中记录的存放所述每个节区的起始内存地址。The second determining subunit is configured to determine, according to the size of each section in the current source file to be processed, the starting memory address for storing each section recorded in the link script of the current source file to be processed.

再一方面,一种计算机系统,所述计算机系统包括至少一个处理器和内存,所述处理器上运行有操作系统,所述操作系统之上运行有编译器,所述编译器用于:In yet another aspect, a computer system includes at least one processor and memory, an operating system runs on the processor, a compiler runs on the operating system, and the compiler is used for:

从前一个源文件的可用内存地址范围中去除前一个源文件的镜像文件所需的内存地址空间,得到当前待处理源文件的可用内存地址范围;Remove the memory address space required by the image file of the previous source file from the available memory address range of the previous source file to obtain the available memory address range of the current source file to be processed;

根据当前待处理源文件的可用内存地址范围生成所述当前待处理源文件的链接脚本,使生成的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址;Generate the link script of the current source file to be processed according to the available memory address range of the current source file to be processed, so that the initial memory address of the image file stored in the generated link script is the available memory of the current source file to be processed The starting address of the address range;

使用生成的链接脚本对所述当前待处理源文件进行编译链接,生成所述当前待处理源文件的镜像文件;Compiling and linking the current source file to be processed by using the generated link script to generate a mirror image file of the current source file to be processed;

所述处理器接收所述编译器发送的所述当前待处理源文件的镜像文件,并进行处理。The processor receives and processes the image file of the source file currently to be processed sent by the compiler.

本发明实施例提供的为多镜像文件分配内存地址空间的方法、编译器和系统,在对每个源文件进行编译前,首先,根据前一个源文件的镜像文件所需的内存地址空间及前一个源文件的可用内存地址范围计算当前待处理源文件的可用内存地址范围;根据当前待处理源文件的可用内存地址范围生成所述当前待处理源文件的链接脚本,使生成的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址;使用生成的链接脚本对所述待处理源文件进行编译链接,生成待处理源文件的镜像文件,由于用于进行编译链接的链接脚本中记录的存放镜像文件的起始内存地址为当前待处理源文件的可用内存地址范围的起始地址,所以能够充分利用内存地址空间。In the method, compiler and system for allocating memory address space for multiple image files provided by the embodiments of the present invention, before compiling each source file, first, according to the memory address space required by the image file of the previous source file and the previous The available memory address range of a source file calculates the available memory address range of the current source file to be processed; the link script of the current source file to be processed is generated according to the available memory address range of the current source file to be processed, so that the generated link script records The initial memory address of storing the image file is the initial address of the available memory address range of the current source file to be processed; use the generated link script to compile and link the source file to be processed to generate a mirror image of the source file to be processed file, since the initial memory address for storing the image file recorded in the link script for compiling and linking is the initial address of the available memory address range of the current source file to be processed, the memory address space can be fully utilized.

附图说明 Description of drawings

为了更清楚地说明本发明实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings that need to be used in the description of the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention. For those skilled in the art, other drawings can also be obtained based on these drawings without creative effort.

图1为本发明实施例提供的一种为多镜像文件分配内存地址空间的方法的流程图;Fig. 1 is a flow chart of a method for allocating memory address space for multiple image files provided by an embodiment of the present invention;

图2为本发明实施例提供的另一种为多镜像文件分配内存地址空间的方法的流程图;Fig. 2 is another kind of flow chart of the method for allocating memory address space for multiple image files provided by the embodiment of the present invention;

图3为图2所示实施例5个源文件时的一种实现流程示意图;Fig. 3 is a kind of implementation flow schematic diagram when 5 source files of the embodiment shown in Fig. 2;

图4为图2所示实施例5个源文件时的另一种实现流程示意图;Fig. 4 is another kind of implementation flow schematic diagram when 5 source files of the embodiment shown in Fig. 2;

图5为本发明实施例提供的一种编译器的结构图;FIG. 5 is a structural diagram of a compiler provided by an embodiment of the present invention;

图6为本发明实施例提供的另一编译器的结构图;FIG. 6 is a structural diagram of another compiler provided by an embodiment of the present invention;

图7为本发明实施例提供的一种计算机系统的结构图。FIG. 7 is a structural diagram of a computer system provided by an embodiment of the present invention.

具体实施方式 Detailed ways

下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some, not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without creative efforts fall within the protection scope of the present invention.

本发明实施例提供了一种为多镜像文件分配内存地址空间的方法,如图1所示,包括:The embodiment of the present invention provides a method for allocating memory address space for multiple image files, as shown in Figure 1, including:

101、根据前一个源文件的镜像文件所需的内存地址空间及前一个源文件的可用内存地址范围计算当前待处理源文件的可用内存地址范围。101. Calculate the available memory address range of the current source file to be processed according to the memory address space required by the image file of the previous source file and the available memory address range of the previous source file.

102、根据当前待处理源文件的可用内存地址范围生成当前待处理源文件的链接脚本,使生成的链接脚本中记录的存放镜像文件的起始内存地址为当前待处理源文件的可用内存地址范围的起始地址。102. Generate the link script of the current source file to be processed according to the available memory address range of the current source file to be processed, so that the starting memory address for storing the image file recorded in the generated link script is the available memory address range of the current source file to be processed The starting address of .

在对每个源文件进行编译链接生成镜像文件前,首先,生成用于进行对源文件进行编译链接的链接脚本,使生成的链接脚本中记录的存放镜像文件的起始内存地址为当前待处理源文件的可用内存地址范围的起始地址,以便于在对当前待处理源文件进行编译链接时,生成的镜像文件分配内存地址空间与前一个生成的镜像文件所使用的内存空间连续。Before compiling and linking each source file to generate an image file, firstly, generate a link script for compiling and linking the source file, so that the initial memory address for storing the image file recorded in the generated link script is currently pending The starting address of the available memory address range of the source file, so that when the current source file to be processed is compiled and linked, the memory address space allocated by the generated image file is continuous with the memory space used by the previous generated image file.

103、使用生成的链接脚本对待处理源文件进行编译链接,生成待处理源文件的镜像文件。103. Compile and link the source file to be processed by using the generated link script to generate a mirror image file of the source file to be processed.

本实施例提供的为多镜像文件分配内存地址空间的方法,在对每个源文件进行编译前,首先,根据前一个源文件的镜像文件所需的内存地址空间及前一个源文件的可用内存地址范围计算当前待处理源文件的可用内存地址范围;根据当前待处理源文件的可用内存地址范围生成所述当前待处理源文件的链接脚本,使生成的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址;使用生成的链接脚本对所述待处理源文件进行编译链接,生成待处理源文件的镜像文件,由于用于进行编译链接的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址,所以能够充分利用内存地址空间。The method for allocating memory address space for multiple image files provided by this embodiment, before each source file is compiled, first, according to the memory address space required by the image file of the previous source file and the available memory of the previous source file The address range calculates the available memory address range of the current source file to be processed; the link script of the current source file to be processed is generated according to the available memory address range of the current source file to be processed, so that the starting point of storing the image file recorded in the generated link script is The initial memory address is the initial address of the available memory address range of the current source file to be processed; the generated link script is used to compile and link the source file to be processed to generate a mirror image file of the source file to be processed. The starting memory address for storing the image file recorded in the linking script of compiling and linking is the starting address of the available memory address range of the current source file to be processed, so the memory address space can be fully utilized.

在为了满足用户需求而不断推出新业务软件的同时,如果处理器仍采用仅包括CPU的单核架构或多核架构实现,这些新业务将很难实现,因此,当前,处理器采用异构多核架构实现,异构多核架构即将不同类型的内核集成在同一块芯片上,在这种架构中,CPU内核所不擅长的浮点运算及信号处理工作,由集成在同一块芯片上的其它可编程内核执行。随着业务软件的增多和内核的增多,就需要更充分、高效的利用芯片的各种资源。其中,地址空间资源就是一种非常重要的资源。本发明实施例提供另一种为多镜像文件分配内存地址空间的方法,该方法采用地址空间紧凑排放的方式,充分利用地址空间。具体如下:While constantly introducing new business software to meet user needs, if the processor is still implemented with a single-core architecture or multi-core architecture that only includes the CPU, these new services will be difficult to realize. Therefore, currently, the processor adopts a heterogeneous multi-core architecture Realization, the heterogeneous multi-core architecture integrates different types of cores on the same chip. In this architecture, the floating-point operations and signal processing that the CPU core is not good at are performed by other programmable cores integrated on the same chip. implement. With the increase of business software and cores, it is necessary to utilize various resources of the chip more fully and efficiently. Among them, the address space resource is a very important resource. The embodiment of the present invention provides another method for allocating memory address space for multiple image files. The method adopts a compact arrangement of address spaces to make full use of the address spaces. details as follows:

如图2所示,包括:As shown in Figure 2, including:

201、根据前一个源文件的镜像文件包含的各个节区的大小计算前一个源文件的镜像文件所需的内存地址空间。201. Calculate the memory address space required by the image file of the previous source file according to the size of each section contained in the image file of the previous source file.

步骤201可用包括:Step 201 may include:

201a、确定前一个源文件的可用内存地址范围的起始地址。201a. Determine the start address of the available memory address range of the previous source file.

201b、从所述起始地址开始,去除前一个源文件的镜像文件所需的内存地址空间。201b. Starting from the starting address, remove the memory address space required by the image file of the previous source file.

具体的,在实施本方案时,可以预先设置一个配置文件(configure File),这个配置文件中记录如表1所示的当前可用内存地址资源及如表2所示的镜像文件所涉及的各个节区的共享属性。Specifically, when implementing this solution, a configuration file (configure File) can be set in advance, which records the currently available memory address resources as shown in Table 1 and the various sections involved in the image file as shown in Table 2. Shared properties of the zone.

Figure BDA00001761976900071
Figure BDA00001761976900071

表1Table 1

关于表1中记录的可用内存地址资源,芯片内存剩余的可用内存地址空间可能并不连续,因此需要逐个记录所有的可用地址空间范围。其中name所指内容代表一块连续地址空间的名称代号;address所指内容代表相应的连续地址空间地址范围的起始地址;len所指内容代表相应的连续地址空间地址范围的长度大小。address和len所指定的值需要和实际的硬件芯片相匹配。Regarding the available memory address resources recorded in Table 1, the remaining available memory address space of the chip memory may not be continuous, so it is necessary to record all available address space ranges one by one. Wherein, the content pointed to by name represents the name code of a continuous address space; the content pointed to by address represents the starting address of the address range of the corresponding continuous address space; the content pointed to by len represents the length of the address range of the corresponding continuous address space. The values specified by address and len need to match the actual hardware chip.

Figure BDA00001761976900081
Figure BDA00001761976900081

表2Table 2

关于表2中记录的各个节区的共享属性,链接脚本内可能存在多个节区的定义,因此需要逐个标记各个节区的共享属性及该节区需要存放的内存区域。当芯片内所有的内存地址空间均连续时,该属性可以省略。其中name所指内容代表节区的名称;group所指内容代表相应节区的共享私有属性,例如这里的all则代表所有核共享的节区,dsps代表所有DSP核共享的节区;core7代表核7私有的节区;memory所指定内容代表相应的节区需要分配到的连续地址空间名称。Regarding the shared attributes of each section recorded in Table 2, there may be multiple section definitions in the link script, so it is necessary to mark the shared attributes of each section and the memory area that the section needs to store one by one. When all memory address spaces in the chip are continuous, this attribute can be omitted. The content referred to by name represents the name of the section; the content referred to by group represents the shared private attribute of the corresponding section, for example, all here represents the section shared by all cores, dsps represents the section shared by all DSP cores; core7 represents the core 7 Private section area; the content specified by memory represents the continuous address space name that the corresponding section area needs to be allocated to.

计算源文件的镜像文件所需的内存地址空间时,根据该源文件的镜像文件包含的各个节区的大小计算该源文件的镜像文件所需的内存地址空间。具体的,根据当前待处理源文件中每个节区的大小确定当前待处理源文件的链接脚本中记录的存放每个节区的起始内存地址。When calculating the memory address space required by the mirror file of the source file, the memory address space required by the mirror file of the source file is calculated according to the size of each section contained in the mirror file of the source file. Specifically, the initial memory address for storing each section recorded in the link script of the current source file to be processed is determined according to the size of each section in the current source file to be processed.

为了便于计算镜像文件中各个节区的大小,在生成该镜像文件时,首先,通过分析当前配置文件的内容,获知当前源文件中各个节区的共享属性,根据各个节区的共享属性确定各个节区的大小,并按照各个节区从大到小对用于对当前源文件进行编译连接链接脚本中定义的节区进行重新排列,同时,在重置的链接脚本中插入一些特别的标记,以便统计链接产生的镜像文件中各类节区的大小。特别的标记可以根据实际需要任意设置,如以不同的阿拉伯数字标识共享不同的节区。In order to facilitate the calculation of the size of each section in the image file, when generating the image file, firstly, by analyzing the content of the current configuration file, the shared attributes of each section in the current source file are known, and each section is determined according to the shared attributes of each section. The size of the section area, and rearrange the section areas defined in the link script used to compile and link the current source file according to each section area from large to small, and at the same time, insert some special tags in the reset link script, In order to count the size of various sections in the image file generated by the link. Special marks can be set arbitrarily according to actual needs, such as using different Arabic numerals to identify and share different sections.

202、根据前一个源文件的镜像文件所需的内存地址空间及前一个源文件的可用内存地址范围计算当前待处理源文件的可用内存地址范围。202. Calculate the available memory address range of the current source file to be processed according to the memory address space required by the image file of the previous source file and the available memory address range of the previous source file.

具体的,从前一个源文件的可用内存地址范围中去除前一个源文件的镜像文件所需的内存地址空间,得到当前待处理源文件的可用内存地址范围。Specifically, the memory address space required by the image file of the previous source file is removed from the available memory address range of the previous source file to obtain the available memory address range of the current source file to be processed.

根据前一个镜像文件的数据更新当前待处理源文件的可用内存地址空间,具体的,首先,确定前一个源文件的可用内存地址范围的起始地址;然后,从确定的起始地址开始,去除前一个源文件的镜像文件所需的内存地址空间。Update the available memory address space of the current source file to be processed according to the data of the previous image file. Specifically, first, determine the starting address of the available memory address range of the previous source file; then, start from the determined starting address, remove The memory address space required by the mirror file of the previous source file.

203、根据当前待处理源文件的可用内存地址范围生成当前待处理源文件的链接脚本,使生成的链接脚本中记录的存放镜像文件的起始内存地址为当前待处理源文件的可用内存地址范围的起始地址。203. Generate the link script of the current source file to be processed according to the available memory address range of the current source file to be processed, so that the starting memory address for storing the image file recorded in the generated link script is the available memory address range of the current source file to be processed The starting address of .

在对每个源文件进行编译链接生成镜像文件前,首先,生成用于进行对源文件进行编译链接的链接脚本,使生成的链接脚本中记录的存放镜像文件的起始内存地址为当前待处理源文件的可用内存地址范围的起始地址,以便于在对当前待处理源文件进行编译链接时,生成的镜像文件分配内存地址空间与前一个生成的镜像文件所使用的内存空间连续。Before compiling and linking each source file to generate an image file, firstly, generate a link script for compiling and linking the source file, so that the initial memory address for storing the image file recorded in the generated link script is currently pending The starting address of the available memory address range of the source file, so that when the current source file to be processed is compiled and linked, the memory address space allocated by the generated image file is continuous with the memory space used by the previous generated image file.

作为本实施例的一种实施方式,步骤202可以通过以下步骤方式实现:As an implementation manner of this embodiment, step 202 may be implemented through the following steps:

203a、将当前待处理源文件中各个节区的共享属性添加到当前待处理源文件中;203a. Add the shared attributes of each section in the current source file to be processed to the current source file to be processed;

203b、根据当前待处理源文件中各个节区的共享属性和当前可用内存地址范围生成当前待处理源文件的链接脚本;203b. Generate a link script of the current source file to be processed according to the shared attributes of each section in the current source file to be processed and the currently available memory address range;

为了简化编译链接流程,也可以将配置文件中各个节区的共享属性添加到源文件的代码上,从而在对源文件进行编译链接的过程中自动生成用于对该源文件进行编译链接的链接脚本,达到编译链接的无缝结合。In order to simplify the process of compiling and linking, the shared attributes of each section in the configuration file can also be added to the code of the source file, so that a link for compiling and linking the source file can be automatically generated during the process of compiling and linking the source file Script to achieve seamless combination of compilation and linking.

具体的,可以通过以下方式实现将配置文件中各个节区的共享属性添加到源文件的代码上,扩展C语言关键字描述变量和各函数的存放位置以及个节区的共享属性,扩展标记的描述可以是以下形式:Specifically, the shared attributes of each section area in the configuration file can be added to the code of the source file in the following ways, the C language keywords are expanded to describe the storage locations of variables and functions, and the shared attributes of each section area are expanded. A description can be of the form:

Figure BDA00001761976900091
Figure BDA00001761976900091

这里的关键字_ _core_ _(all)主要用来描述所指定内容的共享属性,关键字_ _mem_ _主要用来描述所指定内容将要配置的目标内存地址空间。The keyword _ _core_ _(all) here is mainly used to describe the shared attributes of the specified content, and the keyword _ _mem_ _ is mainly used to describe the target memory address space to be configured by the specified content.

通过一个预处理过程,将上述扩展C语言以增加_ _attribute_ _((section(“name”)))的方式转换成标准的C语言。在此预处理过程中,同时根据配置文件configure File中记录的系统可用的地址空间范围产生相应的链接脚本。若预先不设置链接脚本,假设源文件数量为5,本实施方式的流程可以如图3所示。Through a preprocessing process, the above extended C language is converted into standard C language by adding _ _attribute_ _((section("name"))). During this preprocessing process, corresponding link scripts are generated according to the available address space range of the system recorded in the configuration file configure File. If no link script is set in advance, assuming that the number of source files is 5, the flow of this embodiment can be shown in FIG. 3 .

或者,作为本实施例的另一种实施方式,步骤202也可以通过以下方式实现:Alternatively, as another implementation manner of this embodiment, step 202 may also be implemented in the following manner:

根据当前可用内存地址范围修改预设链接脚本中记录的存放镜像文件的起始内存地址,得到当前待处理源文件的链接脚本。According to the current available memory address range, the initial memory address for storing the image file recorded in the preset link script is modified to obtain the link script of the current source file to be processed.

也可以为编译链接预先设置链接脚本,这个预先设置的连接脚本中记录的存放镜像文件的起始内存地址为任意内存地址。在对每个源文件进行编译链接前,对预先设置的链接脚本中记录的存放镜像文件的起始内存地址进行修改,使用预先设置的连接脚本时,假设源文件数量为5,本实施方式的流程可以如图4所示。It is also possible to pre-set a link script for compiling and linking, and the initial memory address for storing the image file recorded in this pre-set link script is an arbitrary memory address. Before compiling and linking each source file, the initial memory address for storing the image file recorded in the preset link script is modified. When using the preset link script, it is assumed that the number of source files is 5. The process can be shown in Figure 4.

204、使用生成的链接脚本对待处理源文件进行编译链接,生成待处理源文件的镜像文件。204. Compile and link the source file to be processed by using the generated link script to generate a mirror image file of the source file to be processed.

本实施例提供的为多镜像文件分配内存地址空间的方法,在对每个源文件进行编译前,首先,从前一个源文件的可用内存地址范围中去除前一个源文件的镜像文件所需的内存地址空间,得到当前待处理源文件的可用内存地址范围;根据当前待处理源文件的可用内存地址范围生成所述当前待处理源文件的链接脚本,使生成的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址;使用生成的链接脚本对所述待处理源文件进行编译链接,生成待处理源文件的镜像文件,由于用于进行编译链接的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址,所以能够充分利用内存地址空间。In the method for allocating memory address space for multiple image files provided by this embodiment, before compiling each source file, at first, remove the memory required by the image file of the previous source file from the available memory address range of the previous source file The address space obtains the available memory address range of the current source file to be processed; the link script of the current source file to be processed is generated according to the available memory address range of the current source file to be processed, so that the image file stored in the generated link script is recorded The initial memory address is the initial address of the available memory address range of the current source file to be processed; the generated link script is used to compile and link the source file to be processed to generate a mirror image file of the source file to be processed. The starting memory address for storing the image file recorded in the linking script for compiling and linking is the starting address of the available memory address range of the current source file to be processed, so the memory address space can be fully utilized.

本发明实施例提供了一种编译器,如图5所示,包括:第一计算单元51、生成单元52、编译链接单元53。An embodiment of the present invention provides a compiler, as shown in FIG. 5 , including: a first computing unit 51 , a generating unit 52 , and a compiling and linking unit 53 .

其中,第一计算单元51,用于根据前一个源文件的镜像文件所需的内存地址空间及前一个源文件的可用内存地址范围计算当前待处理源文件的可用内存地址范围,将得到的所述当前待处理源文件的可用内存地址范围发送至生成单元。Wherein, the first calculation unit 51 is used to calculate the available memory address range of the current source file to be processed according to the memory address space required by the image file of the previous source file and the available memory address range of the previous source file, and obtain all Send the available memory address range of the current source file to be processed to the generating unit.

生成单元52,用于接收所述第一计算单元发送的所述当前待处理源文件的可用内存地址范围,根据当前待处理源文件的可用内存地址范围生成所述当前待处理源文件的链接脚本,使生成的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址,将生成的所述当前待处理源文件的链接脚本发送至编译链接单元;The generation unit 52 is configured to receive the available memory address range of the current source file to be processed sent by the first calculation unit, and generate the link script of the current source file to be processed according to the available memory address range of the current source file to be processed , making the initial memory address of storing the image file recorded in the generated link script be the initial address of the available memory address range of the current source file to be processed, and sending the generated link script of the source file to be processed to Compile the link unit;

编译链接单元53,用于接收所述生成单元发送的所述当前待处理源文件的链接脚本,使用生成的链接脚本对所述待处理源文件进行编译链接,生成待处理源文件的镜像文件。The compiling and linking unit 53 is configured to receive the linking script of the source file to be processed sent by the generating unit, use the generated linking script to compile and link the source file to be processed, and generate an image file of the source file to be processed.

本实施例提供的编译器,在对每个源文件进行编译前,首先,第一计算单元根据前一个源文件的镜像文件所需的内存地址空间及前一个源文件的可用内存地址范围计算当前待处理源文件的可用内存地址范围;生成单元根据当前待处理源文件的可用内存地址范围生成所述当前待处理源文件的链接脚本,使生成的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址;编译链接单元使用生成的链接脚本对所述待处理源文件进行编译链接,生成待处理源文件的镜像文件,由于用于进行编译链接的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址,所以能够充分利用内存地址空间。For the compiler provided in this embodiment, before compiling each source file, first, the first calculation unit calculates the current The available memory address range of the source file to be processed; the generation unit generates the link script of the current source file to be processed according to the available memory address range of the current source file to be processed, so that the initial memory of storing the mirror image file recorded in the generated link script The address is the start address of the available memory address range of the current source file to be processed; the compilation and linking unit uses the generated link script to compile and link the source file to be processed, and generate the image file of the source file to be processed, because it is used for The starting memory address for storing the image file recorded in the linking script for compiling and linking is the starting address of the available memory address range of the current source file to be processed, so the memory address space can be fully utilized.

作为本实施例的一种改进,本发明实施例提供另一种编译器,如图6所示,包括:第二计算单元61、第一计算单元62、生成单元63、编译链接单元64。As an improvement of this embodiment, this embodiment of the present invention provides another compiler, as shown in FIG. 6 , including: a second computing unit 61 , a first computing unit 62 , a generating unit 63 , and a compiling and linking unit 64 .

其中,第一计算单元62包括:第一确定子单元621、去除子单元622;生成单元63包括:添加子单元631、第一生成子单元632、第二生成子单元633、第二确定子单元634。Wherein, the first calculation unit 62 includes: a first determination subunit 621, a removal subunit 622; the generation unit 63 includes: an addition subunit 631, a first generation subunit 632, a second generation subunit 633, a second determination subunit 634.

第二计算单元61,用于根据前一个源文件的镜像文件包含的各个节区的大小计算前一个源文件的镜像文件所需的内存地址空间,将计算得到的前一个源文件的镜像文件所需的内存地址空间发送至所述第一计算单元;The second calculation unit 61 is used to calculate the memory address space required by the image file of the previous source file according to the size of each section contained in the image file of the previous source file, and calculate the image file of the previous source file obtained by calculating Send the required memory address space to the first computing unit;

所述第一计算单元62,用于接收所述第二计算单元发送的前一个源文件的镜像文件所需的内存地址空间。The first computing unit 62 is configured to receive the memory address space required by the image file of the previous source file sent by the second computing unit.

第一计算单元62,用于根据前一个源文件的镜像文件所需的内存地址空间及前一个源文件的可用内存地址范围计算当前待处理源文件的可用内存地址范围,得到所述当前待处理源文件的可用内存地址范围,将得到的所述当前待处理源文件的可用内存地址范围发送至生成单元;The first calculation unit 62 is used to calculate the available memory address range of the current source file to be processed according to the memory address space required by the image file of the previous source file and the available memory address range of the previous source file, to obtain the current pending source file. The available memory address range of the source file, sending the obtained available memory address range of the current source file to be processed to the generation unit;

第一确定子单元621,用于确定前一个源文件的可用内存地址范围的起始地址,并将确定的所述起始地址发送至去除子单元;The first determining subunit 621 is configured to determine the starting address of the available memory address range of the previous source file, and send the determined starting address to the removing subunit;

去除子单元622,用于接收所述确定子单元发送的所述起始地址,从所述起始地址开始,去除前一个源文件的镜像文件所需的内存地址空间。The removing subunit 622 is configured to receive the starting address sent by the determining subunit, and start from the starting address to remove the memory address space required by the image file of the previous source file.

生成单元63,用于接收所述第一计算单元发送的所述当前待处理源文件的可用内存地址范围,根据所述当前待处理源文件的可用内存地址范围生成所述当前待处理源文件的链接脚本,使生成的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址,将生成的所述当前待处理源文件的链接脚本发送至编译链接单元;The generation unit 63 is configured to receive the available memory address range of the current source file to be processed sent by the first calculation unit, and generate the address range of the current source file to be processed according to the available memory address range of the current source file to be processed Link script, make the initial memory address of depositing image file recorded in the link script that generates be the initial address of the available memory address range of described current source file to be processed, the link script of described current source file to be processed will be generated sent to compile link unit;

添加子单元631,用于将所述当前待处理源文件中各个节区的共享属性添加到所述当前待处理源文件中,将所述当前待处理源文件中各个节区的共享属性发送至第一生成子单元,或将所述当前待处理源文件中各个节区的共享属性发送至第二生成子单元;The adding subunit 631 is configured to add the shared attributes of each section in the current source file to be processed to the current source file to be processed, and send the shared attributes of each section in the current source file to be processed to The first generating subunit, or sending the shared attributes of each section in the current source file to be processed to the second generating subunit;

第一生成子单元632,用于接收所述添加子单元发送的所述当前待处理源文件中各个节区的共享属性,根据所述当前待处理源文件中各个节区的共享属性和所述当前可用内存地址范围生成所述当前待处理源文件的链接脚本;或者,The first generation subunit 632 is configured to receive the shared attribute of each section in the current source file to be processed sent by the adding subunit, and according to the shared attribute of each section in the current source file to be processed and the generating a linker script for said currently pending source file for the currently available memory address range; or,

第二生成子单元633,用于接收所述添加子单元发送的所述当前待处理源文件中各个节区的共享属性,根据当前可用内存地址范围修改预设链接脚本中记录的存放镜像文件的起始内存地址,得到所述当前待处理源文件的链接脚本。The second generating subunit 633 is configured to receive the shared attribute of each section in the current source file to be processed sent by the adding subunit, and modify the storage image file recorded in the preset link script according to the currently available memory address range The starting memory address is used to obtain the link script of the current source file to be processed.

第二确定子单元634,用于根据所述当前待处理源文件中每个节区的大小确定所述当前待处理源文件的链接脚本中记录的存放所述每个节区的起始内存地址。The second determining subunit 634 is configured to determine the initial memory address for storing each section recorded in the link script of the current source file to be processed according to the size of each section in the current source file to be processed .

编译链接单元64,用于接收所述生成单元发送的所述当前待处理源文件的链接脚本,使用生成的链接脚本对所述当前待处理源文件进行编译链接,生成所述当前待处理源文件的镜像文件。Compiling and linking unit 64, configured to receive the link script of the current source file to be processed sent by the generating unit, use the generated link script to compile and link the current source file to be processed, and generate the current source file to be processed mirror file.

本实施例提供的编译器,在对每个源文件进行编译前,首先,,第一计算单元根据前一个源文件的镜像文件所需的内存地址空间及前一个源文件的可用内存地址范围计算当前待处理源文件的可用内存地址范围;生成单元根据当前待处理源文件的可用内存地址范围生成所述当前待处理源文件的链接脚本,使生成的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址;编译链接单元使用生成的链接脚本对所述待处理源文件进行编译链接,生成待处理源文件的镜像文件,由于用于进行编译链接的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址,所以能够充分利用内存地址空间。For the compiler provided in this embodiment, before compiling each source file, first, the first calculation unit calculates the memory address space required by the image file of the previous source file and the available memory address range of the previous source file. The available memory address range of the current source file to be processed; the generation unit generates the link script of the current source file to be processed according to the available memory address range of the current source file to be processed, so that the initial storage image file recorded in the generated link script is The memory address is the start address of the available memory address range of the current source file to be processed; the compilation and linking unit uses the generated link script to compile and link the source file to be processed, and generate the image file of the source file to be processed. The initial memory address for storing the image file recorded in the link script for compiling and linking is the initial address of the available memory address range of the current source file to be processed, so the memory address space can be fully utilized.

本实施例提供的为多镜像文件分配内存地址空间的方法、编译器和系统,采用多核编程的方式,减少了多核共享资源的使用维护工作量;对于各个Image划分的内存空间由当前实际可用内存地址空间给出,能够保证空间足够该Image使用,且没有浪费,编译出来的Image能有效的利用内存空间;在编译链接过程中逐个计算各个Image在特定内存的使用情况,直接进行内存划分减少工作量;即使在编译链接前增加业务代码也不需要对内存空间进行重新计算,不会导致内存空间划分的重新调整;内存部署经过一次链接便可得出地址空间分配的优化方案。The method, compiler, and system for allocating memory address space for multi-image files provided in this embodiment adopt the mode of multi-core programming, which reduces the usage and maintenance workload of multi-core shared resources; for the memory space divided by each Image, the current actual available memory The address space is given, which can ensure that the space is enough for the image to use, and there is no waste. The compiled image can effectively use the memory space; in the process of compiling and linking, the usage of each image in the specific memory is calculated one by one, and the memory division is directly performed to reduce the work Even if the business code is added before compiling and linking, there is no need to recalculate the memory space, and it will not cause readjustment of the memory space division; memory deployment can obtain an optimized solution for address space allocation after one link.

本发明实施例还提供了一种计算机系统,如图7所示,包括至少一个处理器72和内存73,所述处理器上运行有操作系统,所述操作系统之上运行有编译器,所述编译器为上述实施例中任一编译器。所述处理器接收所述编译器发送的所述当前待处理源文件的镜像文件,并进行处理。The embodiment of the present invention also provides a computer system, as shown in FIG. 7 , including at least one processor 72 and memory 73, an operating system runs on the processor, a compiler runs on the operating system, and The above-mentioned compiler is any one of the above-mentioned compilers. The processor receives and processes the image file of the source file currently to be processed sent by the compiler.

其中,所述内存73包含多个物理内存页,且所述包含多个物理内存页的内存分为用户态内存区和内核态内存区,所述用户态内存区的物理内存页用于存储用户态数据和指令,所述内核态内存区的物理内存页用于存储内核态数据和指令;所述处理器72通过所述总线,调用所述内存中存储的代码,以用于:当一个线程需要分配内存时,识别所述线程的类型;若所述线程为用户态线程,则从所述用户态内存区为该用户态线程分配内存;若所述线程为内核态线程,则从所述内核态内存区为该内核态线程分配内存。Wherein, the memory 73 includes a plurality of physical memory pages, and the memory that includes a plurality of physical memory pages is divided into a user-mode memory area and a kernel-mode memory area, and the physical memory pages of the user-mode memory area are used to store user State data and instructions, the physical memory pages of the kernel state memory area are used to store kernel state data and instructions; the processor 72 calls the code stored in the memory through the bus, for: when a thread When needing to allocate memory, identify the type of the thread; if the thread is a user-mode thread, allocate memory for the user-mode thread from the user-mode memory area; if the thread is a kernel-mode thread, then allocate memory from the user-mode memory area The kernel-mode memory area allocates memory for the kernel-mode thread.

上述计算机系统还可以进一步包括与总线71相连接的用户接口74。The above computer system may further include a user interface 74 connected to the bus 71 .

可选的,所述处理器72还用于当所述线程需要分配内存时,若操作系统发生缺页异常,则为所述线程的内存分配行为设置用户内存分配行为修饰符;所述用户内存分配行为修饰符用于标记当前内存分配行为由用户态线程触发。Optionally, the processor 72 is also configured to set a user memory allocation behavior modifier for the memory allocation behavior of the thread if a page fault occurs in the operating system when the thread needs to allocate memory; the user memory The allocation behavior modifier is used to mark that the current memory allocation behavior is triggered by a user mode thread.

上述任一计算机系统还可以包括缓存,该缓存可以设置在处理器中,作为该处理器中多个处理器核的共享缓存。需要说明的是,本发明实施例中的缓存通常可以是硬件高速缓存,但不限于最后一级高速缓存,而可以是任何一个被多个处理器核共享的缓存。上述计算机系统不限于多核计算机系统,而可以是任何由多个处理器核共享同一缓存的系统。Any of the above computer systems may further include a cache, which may be set in the processor as a shared cache of multiple processor cores in the processor. It should be noted that the cache in this embodiment of the present invention may generally be a hardware cache, but is not limited to the last level cache, and may be any cache shared by multiple processor cores. The above-mentioned computer system is not limited to a multi-core computer system, but can be any system in which multiple processor cores share the same cache.

本实施例提供的计算机系统,编译器在对每个源文件进行编译前,首先,从前一个源文件的可用内存地址范围中去除前一个源文件的镜像文件所需的内存地址空间,得到当前待处理源文件的可用内存地址范围;根据当前待处理源文件的可用内存地址范围生成所述当前待处理源文件的链接脚本,使生成的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址;使用生成的链接脚本对所述待处理源文件进行编译链接,生成待处理源文件的镜像文件,由于用于进行编译链接的链接脚本中记录的存放镜像文件的起始内存地址为所述当前待处理源文件的可用内存地址范围的起始地址,所以能够充分利用内存地址空间。In the computer system provided by this embodiment, before compiling each source file, the compiler first removes the memory address space required by the image file of the previous source file from the available memory address range of the previous source file, and obtains the Process the available memory address range of the source file; generate the link script of the current source file to be processed according to the available memory address range of the current source file to be processed, so that the initial memory address of the image file stored in the generated link script is Describe the starting address of the available memory address range of the current source file to be processed; use the generated link script to compile and link the source file to be processed to generate a mirror image file of the source file to be processed, because the link script used for compiling and linking The starting memory address for storing the image file recorded in is the starting address of the available memory address range of the current source file to be processed, so the memory address space can be fully utilized.

综上所述,本发明实施例提供的计算机系统中,采用多核编程的方式,减少了多核共享资源的使用维护工作量;编译器对于各个Image划分的内存空间由当前实际可用内存地址空间给出,能够保证空间足够该Image使用,且没有浪费,编译出来的各个Image能有效的利用内存空间;在编译链接过程中逐个计算各个Image在特定内存的使用情况,直接进行内存划分减少工作量;即使在编译链接前增加业务代码也不需要对内存空间进行重新计算,不会导致内存空间划分的重新调整;内存部署经过一次链接便可得出地址空间分配的优化方案。In summary, in the computer system provided by the embodiment of the present invention, the multi-core programming method is adopted to reduce the workload of using and maintaining multi-core shared resources; the memory space divided by the compiler for each Image is given by the currently available memory address space , it can ensure that the space is enough for the image, and there is no waste. The compiled images can effectively use the memory space; in the process of compiling and linking, the usage of each image in the specific memory is calculated one by one, and the memory is divided directly to reduce the workload; even Adding business code before compiling and linking does not need to recalculate the memory space, and will not cause readjustment of memory space division; memory deployment can obtain an optimized solution for address space allocation after one link.

本发明实施例提供的计算机系统中,通过编译器在编译过程中实现存储空间的紧凑排布,避免内存布署需要进行二次链接的情况;且能够自动计算已用存储空间规划可用空间,避免手动反复调整分配空间,提高链接成功率;真正意义上实现了零碎片,内存空间充分利用,避免现有技术中编译出来的Image由于内存块的预先划分导致存在碎片,未能有效的利用内存空间的情况;避免现有技术中内存空间布署对业务代码调整限制的情况,换言之即避免了现有技术中,一旦增加业务代码会导致内存空间划分的重新调整,需要对内存空间进行重新计算的情况。In the computer system provided by the embodiment of the present invention, the compiler realizes the compact arrangement of the storage space during the compiling process, avoiding the situation that memory deployment needs to be linked twice; and can automatically calculate the used storage space and plan the available space, avoiding Manually adjust the allocation space repeatedly to improve the success rate of the link; in the true sense, zero fragmentation is realized, and the memory space is fully utilized, avoiding the fragmentation of the image compiled in the prior art due to the pre-division of the memory block, and the failure to effectively use the memory space situation; avoid the situation in the prior art where memory space deployment imposes restrictions on business code adjustments, in other words, avoid the situation in the prior art that once business codes are added, memory space divisions will be readjusted and memory space needs to be recalculated Condition.

通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到本发明可借助软件加必需的通用硬件的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在可读取的存储介质中,如计算机的软盘,硬盘或光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述的方法。Through the description of the above embodiments, those skilled in the art can clearly understand that the present invention can be realized by means of software plus necessary general-purpose hardware, and of course also by hardware, but in many cases the former is a better embodiment . Based on this understanding, the essence of the technical solution of the present invention or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product is stored in a readable storage medium, such as a floppy disk of a computer , a hard disk or an optical disk, etc., including several instructions for enabling a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in various embodiments of the present invention.

以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应所述以权利要求的保护范围为准。The above is only a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Anyone skilled in the art can easily think of changes or substitutions within the technical scope disclosed in the present invention. Should be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims (13)

1. A method for allocating memory address space for a multi-mirror file, comprising:
calculating the available memory address range of the current source file to be processed according to the memory address space required by the image file of the previous source file and the available memory address range of the previous source file;
generating a link script of the current source file to be processed according to the available memory address range of the current source file to be processed, and enabling a starting memory address, recorded in the generated link script, for storing the image file to be a starting address of the available memory address range of the current source file to be processed;
and compiling and linking the current source file to be processed by using the generated linking script to generate an image file of the current source file to be processed.
2. The method of claim 1, wherein before calculating the available memory address range of the current source file to be processed according to the memory address space required by the image file of the previous source file and the available memory address range of the previous source file, the method further comprises:
and calculating the memory address space required by the image file of the previous source file according to the size of each section contained in the image file of the previous source file.
3. The method according to claim 1 or 2, wherein the calculating the available memory address range of the current source file to be processed according to the memory address space required by the image file of the previous source file and the available memory address range of the previous source file is:
and removing the memory address space required by the image file of the previous source file from the available memory address range of the previous source file to obtain the available memory address range of the current source file to be processed.
4. The method according to any one of claims 1 to 3, wherein calculating the available memory address range of the current source file to be processed according to the memory address space required by the image file of the previous source file and the available memory address range of the previous source file comprises:
determining the starting address of the available memory address range of the previous source file;
and removing the memory address space required by the mirror image file of the previous source file from the starting address.
5. The method according to any one of claims 1 to 4, wherein the generating a link script of the current source file to be processed according to the available memory address range of the current source file to be processed comprises:
adding the shared attribute of each section in the current source file to be processed into the current source file to be processed;
generating a link script of the current source file to be processed according to the sharing attribute of each section in the current source file to be processed and the current available memory address range; or,
and modifying the initial memory address for storing the image file recorded in the preset link script according to the current available memory address range to obtain the link script of the current source file to be processed.
6. The method according to any one of claims 1 to 5, wherein the generating a link script of the current source file to be processed according to the available memory address range of the current source file to be processed comprises:
and determining the initial memory address for storing each section recorded in the link script of the current source file to be processed according to the size of each section in the current source file to be processed.
7. A compiler, comprising:
the first calculation unit is used for calculating the available memory address range of the current source file to be processed according to the memory address space required by the image file of the previous source file and the available memory address range of the previous source file, and sending the obtained available memory address range of the current source file to be processed to the generation unit;
the generating unit is used for receiving the available memory address range of the current source file to be processed sent by the first computing unit, generating a link script of the current source file to be processed according to the available memory address range of the current source file to be processed, enabling a starting memory address recorded in the generated link script and used for storing the image file to be a starting address of the available memory address range of the current source file to be processed, and sending the generated link script of the current source file to be processed to the compiling and linking unit;
and the compiling and linking unit is used for receiving the link script of the current source file to be processed sent by the generating unit, compiling and linking the current source file to be processed by using the generated link script, and generating an image file of the current source file to be processed.
8. The compiler of claim 7, further comprising:
the second calculation unit is used for calculating the memory address space required by the image file of the previous source file according to the size of each section contained in the image file of the previous source file and sending the calculated memory address space required by the image file of the previous source file to the first calculation unit;
the first computing unit is further configured to receive a memory address space required by an image file of a previous source file sent by the second computing unit.
9. The apparatus according to claim 7 or 8, wherein the first calculating unit calculates the available memory address range of the current source file to be processed according to the memory address space required by the image file of the previous source file and the available memory address range of the previous source file as follows: the first computing unit removes the memory address space required by the image file of the previous source file from the available memory address range of the previous source file to obtain the available memory address range of the current source file to be processed.
10. The apparatus according to any one of claims 7-9, wherein the first computing unit comprises:
the first determining subunit is used for determining a starting address of an available memory address range of a previous source file and sending the determined starting address to the removing subunit;
and the removing subunit is used for receiving the starting address sent by the determining subunit and removing the memory address space required by the image file of the previous source file from the starting address.
11. The compiler of any one of claims 7-10, wherein the generating unit comprises:
the adding subunit is configured to add the shared attribute of each section in the current source file to be processed to the current source file to be processed, and send the shared attribute of each section in the current source file to be processed to the first generating subunit, or send the shared attribute of each section in the current source file to be processed to the second generating subunit;
the first generating subunit is configured to receive the shared attribute of each section in the current source file to be processed, which is sent by the adding subunit, and generate a link script of the current source file to be processed according to the shared attribute of each section in the current source file to be processed and the current available memory address range; or,
and the second generating subunit is configured to receive the shared attribute of each section in the current source file to be processed, which is sent by the adding subunit, and modify the initial memory address, recorded in a preset link script, for storing the image file according to the current available memory address range, to obtain the link script of the current source file to be processed.
12. The compiler of any one of claims 7-11, wherein the generating unit comprises:
and the second determining subunit is configured to determine, according to the size of each section in the current source file to be processed, a starting memory address, which is recorded in a link script of the current source file to be processed and used for storing each section, of the current source file to be processed.
13. A computer system, comprising at least one processor and a memory, wherein an operating system runs on the processor, and wherein a compiler runs on the operating system, and wherein the compiler is configured to:
removing a memory address space required by a mirror image file of a previous source file from an available memory address range of the previous source file to obtain an available memory address range of a current source file to be processed;
generating a link script of a current source file to be processed according to an available memory address range of the current source file to be processed, and enabling a starting memory address, recorded in the generated link script, for storing an image file to be a starting address of the available memory address range of the current source file to be processed;
compiling and linking the current source file to be processed by using the generated linking script to generate a mirror image file of the current source file to be processed;
and the processor receives and processes the image file of the current source file to be processed, which is sent by the compiler.
CN201210194345.6A 2012-06-13 2012-06-13 Method, compiler and system for distributing memory address space for image files Active CN102750364B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201210194345.6A CN102750364B (en) 2012-06-13 2012-06-13 Method, compiler and system for distributing memory address space for image files

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201210194345.6A CN102750364B (en) 2012-06-13 2012-06-13 Method, compiler and system for distributing memory address space for image files

Publications (2)

Publication Number Publication Date
CN102750364A true CN102750364A (en) 2012-10-24
CN102750364B CN102750364B (en) 2014-08-13

Family

ID=47030549

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201210194345.6A Active CN102750364B (en) 2012-06-13 2012-06-13 Method, compiler and system for distributing memory address space for image files

Country Status (1)

Country Link
CN (1) CN102750364B (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103544042A (en) * 2013-10-15 2014-01-29 广东威创视讯科技股份有限公司 Image file generation method and compiler
CN106445589A (en) * 2016-09-08 2017-02-22 百富计算机技术(深圳)有限公司 Application loading method and apparatus for small embedded system
CN106681771A (en) * 2016-12-30 2017-05-17 合网络技术(北京)有限公司 System reinstallation method and device
CN108304189A (en) * 2016-08-29 2018-07-20 迈普通信技术股份有限公司 More mirroring device software compilation methods, device and equipment
CN109683985A (en) * 2018-12-19 2019-04-26 中国电子科技集团公司第五十四研究所 A kind of more image starting methods of DSP based on AIS order
CN111367787A (en) * 2018-12-26 2020-07-03 阿里巴巴集团控股有限公司 Method and device for checking page script object leakage in application
CN113127430A (en) * 2019-12-30 2021-07-16 北京懿医云科技有限公司 Mirror image information processing method and device, computer readable medium and electronic equipment

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7036118B1 (en) * 2001-12-20 2006-04-25 Mindspeed Technologies, Inc. System for executing computer programs on a limited-memory computing machine
CN101661397A (en) * 2008-08-29 2010-03-03 宇龙计算机通信科技(深圳)有限公司 Method for realizing dynamic loading of program and method and equipment for generating mapping file
CN102135904A (en) * 2011-03-11 2011-07-27 华为技术有限公司 Multi-core target system oriented mapping method and device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7036118B1 (en) * 2001-12-20 2006-04-25 Mindspeed Technologies, Inc. System for executing computer programs on a limited-memory computing machine
CN101661397A (en) * 2008-08-29 2010-03-03 宇龙计算机通信科技(深圳)有限公司 Method for realizing dynamic loading of program and method and equipment for generating mapping file
CN102135904A (en) * 2011-03-11 2011-07-27 华为技术有限公司 Multi-core target system oriented mapping method and device

Cited By (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103544042A (en) * 2013-10-15 2014-01-29 广东威创视讯科技股份有限公司 Image file generation method and compiler
CN108304189A (en) * 2016-08-29 2018-07-20 迈普通信技术股份有限公司 More mirroring device software compilation methods, device and equipment
CN108304189B (en) * 2016-08-29 2021-03-12 迈普通信技术股份有限公司 Multi-mirror image equipment software compiling method, device and equipment
CN106445589A (en) * 2016-09-08 2017-02-22 百富计算机技术(深圳)有限公司 Application loading method and apparatus for small embedded system
CN106681771A (en) * 2016-12-30 2017-05-17 合网络技术(北京)有限公司 System reinstallation method and device
CN106681771B (en) * 2016-12-30 2020-12-29 阿里巴巴(中国)有限公司 System reinstallation method and device
CN109683985A (en) * 2018-12-19 2019-04-26 中国电子科技集团公司第五十四研究所 A kind of more image starting methods of DSP based on AIS order
CN109683985B (en) * 2018-12-19 2021-10-22 中国电子科技集团公司第五十四研究所 DSP multi-image starting method based on AIS command
CN111367787A (en) * 2018-12-26 2020-07-03 阿里巴巴集团控股有限公司 Method and device for checking page script object leakage in application
CN111367787B (en) * 2018-12-26 2023-06-20 阿里巴巴集团控股有限公司 Method and device for checking leakage of page script object in application
CN113127430A (en) * 2019-12-30 2021-07-16 北京懿医云科技有限公司 Mirror image information processing method and device, computer readable medium and electronic equipment
CN113127430B (en) * 2019-12-30 2024-05-03 北京懿医云科技有限公司 Mirror image information processing method, mirror image information processing device, computer readable medium and electronic equipment

Also Published As

Publication number Publication date
CN102750364B (en) 2014-08-13

Similar Documents

Publication Publication Date Title
CN102750364B (en) Method, compiler and system for distributing memory address space for image files
US8645930B2 (en) System and method for obfuscation by common function and common function prototype
CN112905472B (en) Kernel debugging system and method
CN105808219B (en) A kind of memory headroom distribution method and device
US9454481B2 (en) Affinity group access to global data
US10127151B2 (en) Dynamically sized locals with precise garbage collection reporting
US20140310484A1 (en) System and method for globally addressable gpu memory
CN102109980B (en) The method and apparatus of adaptive prefetching operation is performed in trustship runtime environment
US10229044B2 (en) Conditional stack frame allocation
US8910136B2 (en) Generating code that calls functions based on types of memory
CN111344667B (en) System and method for compiling and executing code within virtual memory sub-pages of one or more virtual memory pages
US9864518B2 (en) Assigning home memory addresses to function call parameters
US20080077930A1 (en) Workload Partitioning in a Parallel System with Hetergeneous Alignment Constraints
US20070300210A1 (en) Compiling device, list vector area assignment optimization method, and computer-readable recording medium having compiler program recorded thereon
US7991962B2 (en) System and method of using threads and thread-local storage
US8769498B2 (en) Warning of register and storage area assignment errors
CN105677481A (en) Method and system for processing data and electronic equipment
US20150046913A1 (en) Data splitting for multi-instantiated objects
CN112988148B (en) Multi-block-chain and cross-platform supporting SDK generation method and device
US9448929B1 (en) Memory allocation folding based on object dominance
CN106547603B (en) Method and device for reducing garbage collection time of golang language system
US12204943B1 (en) System and method for dynamically allocating computer resources to a data processing pipeline
JP2011181114A (en) Device and method for converting program, and recording medium
US9304921B2 (en) Affinity group access to global data
Lee et al. Optimistic Global Function Merger

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20211221

Address after: 450046 Floor 9, building 1, Zhengshang Boya Plaza, Longzihu wisdom Island, Zhengdong New Area, Zhengzhou City, Henan Province

Patentee after: xFusion Digital Technologies Co., Ltd.

Address before: 518129 Bantian HUAWEI headquarters office building, Longgang District, Guangdong, Shenzhen

Patentee before: HUAWEI TECHNOLOGIES Co.,Ltd.

TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20250305

Address after: 10/F, Chuangzhi Tiandi Building, Dongshigeng Street, Zhongdao East Road, Longzihu Wisdom Island, Zhengdong New District, Zhengzhou City, Henan Province, 450000

Patentee after: Henan Kunlun Technology Co.,Ltd.

Country or region after: China

Patentee after: xFusion Digital Technologies Co., Ltd.

Address before: 450046 Floor 9, building 1, Zhengshang Boya Plaza, Longzihu wisdom Island, Zhengdong New Area, Zhengzhou City, Henan Province

Patentee before: xFusion Digital Technologies Co., Ltd.

Country or region before: China