这是用户在 2025-7-3 13:43 为 https://patents.google.com/patent/US20090307676A1/en 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?

 Patents  专利

Search tools  搜索工具 Text  文本 Classification  分类 Chemistry  化学 Measure  测量 Numbers  数字 Full documents  完整文档 Title  标题 Abstract  摘要 Claims  权利要求 All  所有 Any  任意 Exact  精确 Not   Add AND condition  添加 AND 条件 These CPCs and their children   这些 CPC 及其子项 These exact CPCs   这些确切的 CPC Add AND condition  添加 AND 条件
Exact  确切 Exact Batch  精确批量 Similar  相似 Substructure  子结构 Substructure (SMARTS)  子结构(SMARTS) Full documents  全文 Claims only  仅权利要求书 Add AND condition  添加 AND 条件
Add AND condition  添加 AND 条件
Application Numbers  申请号 Publication Numbers  公开号 Either  任一 Add AND condition  添加 AND 条件

Dead Functions Elimination in Dynamic Linked Libraries for Code Size Reduction of Operating Systems in Embedded Systems
动态链接库中的死函数消除以减少嵌入式系统中操作系统的代码大小

Abstract  摘要

This invention relates to a method for reducing the size of a set of computer code by replacing unused functions in the set of code with void functions having no operative content. The invention may be applied to a core operating system in order to reduce the amount of code that is permanently loaded on a computing device while the device is operating, thereby potentially reducing the requirements for both read-only non-execute-in-place memory and randomly addressable memory. The removed functionality may be provided separately in read-only memory if desired, so that it can be loaded when needed.
本发明涉及一种通过用无操作内容的空函数替换代码集中的未使用函数来减小代码集大小的方法。该发明可应用于核心操作系统,以减少设备在运行时永久加载的代码量,从而可能降低对只读非执行内存和随机寻址内存的要求。如果需要,可以单独在只读内存中提供被移除的功能,以便在需要时加载。

Images (4)  图片 (4)

Classifications  分类

G06F9/44521 Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
G06F9/44521 动态链接或加载;加载时或加载后的链接编辑,例如 Java 类加载
View 4 more classifications
查看更多分类

Landscapes  技术领域

Show more  显示更多

US20090307676A1

United States

Inventor
Howard Price
Aleksandar Antonic
Current Assignee
Nokia Inc

发明人 霍华德·普莱斯 亚历山大·安东尼 当前权利人 索尼公司

Worldwide applications  全球应用
2006 GB GB 2007 US WO EP

Application US12/295,883 events
申请 US12/295,883 事件
2009-01-29
Assigned to SYMBIAN SOFTWARE LIMITED
分配给 SYMBIAN SOFTWARE LIMITED
2009-02-11
Assigned to NOKIA CORPORATION
分配给 NOKIA CORPORATION
Abandoned  已放弃

Description  描述

  • [0001]
    This invention relates to reducing the size of computer code, and in particular but not exclusively to reducing the size of software to be embedded in a computing device.
    本发明涉及减小计算机代码的大小,特别是但不限于减小嵌入在计算设备中的软件的大小。
  • [0002]
    The term computing device as used herein is to be expansively construed to cover any form of electrical computing device and includes, data recording devices, computers of any type or form, including hand held and personal computers such as Personal Digital Assistants (PDAs), and communication devices of any form factor, including mobile phones, smart phones, communicators which combine communications, image recording and/or playback, and computing functionality within a single device, and other forms of wireless and wired information devices, including digital cameras, MP3 and other music players, and digital radios.
    此处使用的术语"计算设备"应广泛解释,涵盖任何形式的电气计算设备,包括数据记录设备、各种类型或形式的计算机,包括手持式和个人计算机(如个人数字助理(PDA)),以及任何形式的通信设备,包括手机、智能手机、集通信、图像记录和/或播放以及计算功能于一体的通信器,以及其他形式的无线和有线信息设备,包括数码相机、MP3 和其他音乐播放器以及数码收音机。
  • [0003]
    Modern computing devices generally contain multiple types of memory. Memory can be broadly categorised into two types:
    现代计算设备通常包含多种类型的内存。内存可以大致分为两种类型:
      • Memory that can be used for programs that eXecute In Place (XIP), that is where the programs do not need to be loaded into a different form of memory in order to execute. The various types of RAM (Random Access Memory) are the most prominent examples of this type. However, because RAM is volatile and loses its contents when powered down, many devices include smaller amounts of the more expensive but slower varieties of non-volatile XIP memory such as NOR Flash.
        可用于就地执行(XIP)程序的内存,即程序无需加载到不同形式的内存中以执行。各种类型的 RAM(随机存取存储器)是这种类型的突出例子。然而,由于 RAM 是易失性的,在断电时会丢失内容,因此许多设备包含更昂贵但速度较慢的非易失性 XIP 存储器,如 NOR Flash 等较小量的内存。
      • Memory that can be used for storage, but not for XIP; generally this is because it can only be accessed sequentially or in blocks, rather than being randomly addressable. Disk drives and NAND Flash are prominent examples of this type. Programs kept in storage memory have to be copied to XIP memory in order to be able to run.
        可用于存储但不可用于 XIP 的内存;通常这是因为它只能顺序访问或分块访问,而不是随机寻址。磁盘驱动器和 NAND Flash 是这种类型的突出例子。存储内存中保存的程序必须复制到 XIP 内存中才能运行。
  • [0006]
    There is additionally one significant difference between these two types of memory; XIP memory is much more expensive than memory which can only be used for storage. Because there are considerable cost pressures on the manufacture of modern computing devices, including portable devices such as mobile telephones which are aimed at the price sensitive mass market, it is desirable that such devices should wherever possible minimise their requirements for XIP memory.
    这两种类型的存储器还有一个重要区别;XIP 存储器比只能用于存储的存储器贵得多。由于现代计算设备(包括面向价格敏感的大众市场的便携式设备,如移动电话)的制造面临相当大的成本压力,因此希望这些设备尽可能最大限度地减少对 XIP 存储器的需求。
  • [0007]
    It is known that there is a requirement for computing devices to be provided with software that is essential to the proper functioning of the device in some type of permanent non-volatile storage as part of the manufacturing process. Such software commonly includes data and programs that are necessary to the boot-up procedures that run when the device is powered up, or that provide Operating System (OS) services that are required frequently, or that provide critical applications.
    众所周知,计算设备需要在制造过程中以某种永久性非易失性存储形式提供对其正常运行至关重要的软件。此类软件通常包括在设备通电时运行的启动过程中所需的数据和程序,或提供频繁需要的操作系统(OS)服务,或提供关键应用程序。
  • [0008]
    Devices that keep as much as possible of this type of software in storage memory, copying it to XIP memory (loading it) when needed and releasing the XIP memory when no longer needed (unloading it), are able to minimise their manufacturing costs compared to devices that keep more of this software in XIP memory.
    将尽可能多的此类软件保存在存储器中,并在需要时将其复制到 XIP 存储器(加载它),在不再需要时释放 XIP 存储器(卸载它)的设备,能够与将更多的此类软件保存在 XIP 存储器中的设备相比,最大限度地降低其制造成本。
  • [0009]
    More specifically, where the core operating system (OS) of a device has been provided in storage memory at manufacture time, it generally needs to be copied as an entire OS image from storage to XIP memory as part of the startup (boot) process. The term “core OS” is used here in a general sense to refer to the parts of an OS that are essential to the basic operation of a computing device. An “OS image” is a file representing the entirety of the OS software. The size of an OS image is thus the footprint of the OS when stored in memory.
    更具体地说,如果设备的核心操作系统(OS)在制造时已提供在存储器中,那么它通常需要在启动(boot)过程的一部分中,将整个 OS 镜像从存储器复制到 XIP 存储器。在这里,“核心 OS”一词是广义上用来指代对计算设备的基本操作至关重要的 OS 部分。“OS 镜像”是一个代表整个 OS 软件的文件。因此,OS 镜像的大小是 OS 在存储器中的占用空间。
  • [0010]
    In general, once loaded into XIP memory an OS image cannot be practically unloaded, even in part; it is known to those skilled in the art that because such OS images are typically built using a technique known as static linkage, the memory locations they occupy must be regarded as reserved and are not available for reuse by other software.
    一般来说,一旦操作系统镜像加载到 XIP 内存中,实际上就不能卸载,即使部分也不能;本领域技术人员知道,由于这些操作系统镜像通常使用一种称为静态链接的技术构建,它们占用的内存位置必须被视为保留,并且不可供其他软件重用。
  • [0011]
    A device that minimises the size of the core operating system will be able to minimise the fixed cost of providing XIP memory dedicated for its use, thus minimising the requirements of the device for XIP memory and making it less expensive to buy and more accessible to the general public. It also provides the benefit that less storage memory is required to store the core OS.
    一种能够最小化核心操作系统大小的设备将能够最小化为其专用 XIP 内存的固定成本,从而降低设备对 XIP 内存的需求,并使其购买成本更低,更容易被大众接受。它还提供了减少存储内存需求以存储核心操作系统的优势。
  • [0012]
    Where manufacturers of computing devices provide such devices as families of products, with each member of a family exhibiting different functionality but being developed from the same or similar software, it is desirable from a device manufacturer's perspective for all the members of a family of products to include compatible core operating systems. It is known that this both decreases development costs and increases reliability. Furthermore, where such devices are open and permit the post-manufacture installation of software modules providing additional functionality, compatible core operating systems may enable the utilisation of the same such software modules across an entire family of products.
    当计算设备制造商将此类设备作为产品系列提供,其中每个系列成员具有不同功能但由相同或相似的软件开发时,从设备制造商的角度来看,希望产品系列的所有成员都包含兼容的核心操作系统。众所周知,这既降低了开发成本,又提高了可靠性。此外,当此类设备是开放的并允许在制造后安装提供附加功能的软件模块时,兼容的核心操作系统可以使得同一系列产品的所有设备都能利用相同的软件模块。
  • [0013]
    In the market for computing devices, and especially portable devices such as mobile telephones, related members of product families are typically differentiated by price points and by feature sets. In general, lower priced members of the product family are provided with a lesser feature set (either hardware or software related). This is a well-known phenomenon; see, for example, the account at http://news.bbc.co.uk/2/hi/business/5274352.stm which explains that:
    在计算设备市场,尤其是移动电话等便携设备中,产品系列的相关成员通常通过价格点和功能集来区分。一般来说,产品系列中价格较低的成员会提供较少的功能集(无论是硬件还是软件相关的)。这是一个众所周知的现象;例如,参考 http://news.bbc.co.uk/2/hi/business/5274352.stm 的报道,该报道解释了这一点:
  • [0014]
    “In the hi-tech world it is common to produce a high-specification product, sold at a premium price, and then sell the same product more cheaply with some of the functions disabled.”
    “在高科技领域,通常生产一种高规格的产品,以高价出售,然后禁用部分功能以更低的价格销售相同的产品。”
  • [0015]
    If, for reasons of maintaining OS compatibility within a product family, a core operating system that offers support for a full range of features has to be installed on a member of the product family that was designed to offer a lesser range of features, it is clear that those portions of the OS that offer support for features that are not present constitute wasted memory. If the core OS image is built using static linkage, it will generally not be feasible to reuse the wasted memory addresses occupied by the code implementing these unused features. This is because the core OS image constitutes a monolithic block of code in which memory addresses are written into the programs and it would not be practical to interleave additional code into the wasted addresses associated with OS code that is not used.
    如果出于保持产品系列内操作系统兼容性的原因,一个提供全面功能支持的核心操作系统必须安装在原本设计功能范围较窄的产品系列成员上,那么很显然,那些支持不存在功能部分的操作系统就构成了浪费的内存。如果核心操作系统镜像使用静态链接构建,通常将无法重用由实现这些未使用功能的代码所占据的浪费内存地址。这是因为核心操作系统镜像构成一个代码的单一整体块,其中内存地址写入程序,并且将额外的代码插入到未使用的操作系统代码相关联的浪费地址中并不切实际。
  • [0016]
    On computing devices which copy the core OS from storage to XIP memory, including support for unavailable features bloats the operating system and adds to manufacturing costs without contributing any value. It also increases start-up time, as the support code needs to be copied from storage to XIP memory even though it will not be used.
    在将核心操作系统从存储器复制到 XIP 存储器的计算设备上,对不可用功能的支持会膨胀操作系统并增加制造成本,而不会带来任何价值。它还会增加启动时间,因为即使这些支持代码不会被使用,也需要从存储器复制到 XIP 存储器。
  • [0017]
    It is of course possible to manufacture an alternative version of the core operating system without these unused portions. However, such a version would necessarily abandon a number of the considerable economic benefits to both the manufacturer and its customers of maintaining a coherent product family in two significant respects.
    当然,可以制造一个不包含这些未使用部分的操作系统核心的替代版本。然而,这种版本将不可避免地放弃在两个重要方面维持一个统一产品系列给制造商及其客户带来的相当大的经济效益。
      • 1. Such a version of the core OS may not benefit from compatibility with the original, full, version. In particular, any software installed post-manufacture that relied on code that was supposed to reside in the fully featured version of the core OS would fail to work.
        1. 这种核心操作系统的版本可能无法从与原始完整版本兼容中获益。特别是,任何在制造后安装的依赖于本应存在于核心操作系统完整版本中的代码的软件将无法工作。
      • 2. Because an alternative version of the OS would fragment the product family it would require separate development and testing, thereby increasing development costs and time to market.
        2. 因为操作系统的另一个版本会分散产品系列,这将需要单独的开发和测试,从而增加开发成本和市场推出时间。
  • [0020]
    It is thus desirable to provide a way of removing unused functions, and thereby reducing the size of a set of code, while mitigating the problems set out above.
    因此,提供一种删除未使用函数的方法,从而在减轻上述问题的情况下减小代码集的大小,这是可取的。
  • [0021]
    According to a first aspect of the present invention there is provided a method of reducing the size of a set of computer code intended for use in a computing device, the code comprising a plurality of files, each specifying one or more functions for performing computing tasks, the method comprising: identifying functions within the set of code that: i) are available to be called by others of the functions; and ii) will not be called by others of the functions when the files are executed on the computing device; and removing from the set of code at least part of the content defining the identified functions while retaining, in place of each identified function, a void function of reduced size.
    根据本发明的一个方面,提供了一种减小用于计算设备的一组计算机代码大小的方法,所述代码包括多个文件,每个文件指定一个或多个用于执行计算任务的函数,所述方法包括:识别所述代码组中的函数,这些函数:i) 可被组内其他函数调用;以及 ii) 在文件在计算设备上执行时不会被组内其他函数调用;并从所述代码组中至少部分移除定义所识别函数的内容,同时保留每个所识别函数的位置处一个尺寸更小的空函数。
  • [0022]
    The void function preferably contains no operative code.
    该空函数最好不包含可执行代码。
  • [0023]
    Each of the identified functions in the set of code is preferably associated with an ordinal number specifying the position of the function within a defined order, and, for each identified function, the step of removing content preferably results in the creation of a void function having the same ordinal number as the identified function.
    代码集中的每个已识别函数最好与一个序号相关联,该序号指定了函数在定义顺序中的位置,并且对于每个已识别的函数,移除内容的步骤最好创建一个与已识别函数具有相同序号的空函数。
  • [0024]
    The set of code may be an operating system or a part of an operating system.
    该代码集可能是一个操作系统或操作系统的部分。
  • [0025]
    The said identified functions are preferably exported functions.
    所述已识别的函数优选为导出函数。
  • [0026]
    The method may further comprise, for at least one of the files containing one or more void functions, creating complementary code for the respective file, the complementary code containing functionality that was removed in the said step of removing at least part of the content, such that a combination of: i) the reduced file containing one or more void functions, and ii) the complementary code, provides functionality equivalent to that of the original file.
    该方法还可能包括,对于包含一个或多个空函数的至少一个文件,为相应文件创建补充代码,该补充代码包含在删除至少部分内容所述步骤中移除的功能,使得:i) 包含一个或多个空函数的减少文件,和 ii) 补充代码的组合,提供与原始文件等效的功能。
  • [0027]
    The method may further comprise the step of storing: i) the set of code, including the reduced file, and ii) the complementary code as separately loadable files in storage memory of the computing device in which code cannot execute in place.
    该方法还可能包括存储步骤:i) 包含减少文件的代码集,和 ii) 作为可单独加载文件存储在计算设备的存储内存中的补充代码,其中代码不能就地执行。
  • [0028]
    The method may further comprise providing a linking arrangement configured to link between functions in the reduced set of code and functions in the complementary code, such that all functionality provided by the original set of code can be provided by the combination of the reduced set of code and the complementary code.
    该方法还可进一步包括提供一种链接配置,用于在代码的减少集和补充代码中的函数之间进行链接,以便原始代码集提供的所有功能都可以由减少集和补充代码的组合来提供。
  • [0029]
    The method may further comprise the step of storing: i) the reduced set of code, including any void functions, and ii) each file that contains identified functions, in its original form, as separately loadable files in storage memory of the computing device in which code cannot execute in place.
    该方法还可进一步包括存储步骤:i) 减少集的代码,包括任何空函数,以及 ii) 包含已识别函数的每个文件,以其原始形式,作为可单独加载的文件存储在计算设备的存储内存中,其中代码不能就地执行。
  • [0030]
    The method may further comprise providing a linking arrangement configured to link between functions in the reduced set of code and functions in the said separately loadable files, such that all functionality provided by the original set of code can be provided by the combination of the reduced set of code and the separately loadable files.
    该方法还可进一步包括提供一个链接配置,用于在代码的减少集和所述单独可加载文件中的函数之间进行链接,以便原始代码集提供的所有功能都可以由减少集和单独可加载文件的组合来提供。
  • [0031]
    The method may further comprise removing from the set of code any files containing only void functions.
    该方法还可进一步包括从代码集中删除仅包含空函数的任何文件。
  • [0032]
    The method may further comprise storing, in storage memory of the computing device in which code cannot execute in place, and as separately loadable files, the said removed files in the form in which they existed prior to the step of removing content defining the said identified functions.
    该方法还可能包括将所述已删除文件以在删除定义所述已识别函数的内容的步骤之前它们存在的形式存储在计算设备的存储内存中,并且作为可单独加载的文件。
  • [0033]
    The method may further comprise the steps of: identifying further functions within the set of code that: i) are available to be called by other functions within the same files as the said further functions; and ii) will not be called by other functions when the files are executed on the computing device; and removing from the set of code the identified further functions.
    该方法还可能包括以下步骤:识别代码集中进一步的功能,这些功能:i) 可供同一文件中的其他功能(即所述进一步功能)调用;以及 ii) 当文件在计算设备上执行时不会被其他功能调用;并从代码集中删除已识别的进一步功能。
  • [0034]
    According to a second aspect of the present invention there is provided a set of code intended for use on a computing device, the set of code comprising a plurality of files, each specifying one or more functions for performing computing tasks, wherein those of the functions that: i) are available to be called by others of the functions; and ii) will not be called by others of the functions when the files are executed on the computing device; are present in the set of code only as void functions having no operative code.
    根据本发明第二方面,提供一组用于计算设备的代码,该代码集包括多个文件,每个文件指定一个或多个用于执行计算任务的函数,其中那些:i) 可供其他函数调用;ii) 在文件在计算设备上执行时不会被其他函数调用;的函数,仅以没有操作代码的空函数形式存在于代码集中。
  • [0035]
    According to a third aspect of the present invention there is provided an operating system comprising the set of code as defined above.
    根据本发明第三方面,提供一种操作系统,包括上述的代码集。
  • [0036]
    According to a fourth aspect of the present invention there is provided a computing device having non-volatile memory, the memory containing the set of code defined above. The memory may be storage memory in which code cannot execute in place.
    根据本发明第四方面,提供一种具有非易失性存储器的计算设备,该存储器包含上述代码集。该存储器可以是存储内存,其中代码不能就地执行。
  • [0037]
    The memory may additionally contain, as one or more separately loadable files, complementary code including operative functions, the complementary code being arranged for execution with one or more of the void functions to perform computing tasks.
    该存储器还可以包含作为一个或多个可单独加载的文件的形式的补充代码,包括可操作函数,该补充代码被安排与一个或多个空函数一起执行以完成计算任务。
  • [0038]
    Each void function may be associated with an ordinal number specifying the position of the function within a defined order, and the complementary code may be arranged to be invoked by linking via an ordinal number associated with a void function in the set of code.
    每个空函数可以与一个序号相关联,该序号指定了函数在定义顺序中的位置,并且补充代码可以排列为通过关联于代码集中的一个空函数的序号进行链接来调用。
  • [0039]
    Alternatively or in addition, the memory may contain, as one or more separately loadable files, operative functions each associated with one of the void functions.
    或者另外,或者除此之外,内存可以包含一个或多个可单独加载的文件,其中每个操作函数都与一个空函数相关联。
  • [0040]
    As will be seen from the following discussion, embodiments of the invention enable the RAM requirements of differently featured models of computing devices belonging to the same family to be matched to the feature level of particular models while retaining compatibility with other models in the same family. Embodiments of the invention may be particularly suitable for those devices where a core operating system image is provided in NAND Flash or other types of non-executable non-volatile storage memory, and where that image is copied into RAM at boot. The preferred embodiment of the invention involves identifying those functions that are unused within the core OS image, removing them from the executables they are found in, replacing them with stubs to ensure binary compatibility for those functions that remain, and building a revised core OS image using these “tiny variants” of the affected executables. A version of the executable containing the full version of the removed functions is then placed as a separately loadable module in storage memory for any after-market applications that may require them.
    从以下讨论中可以看出,本发明的实施方式能够使同一系列的不同功能计算设备的 RAM 需求与特定型号的功能级别相匹配,同时保持与同一系列其他型号的兼容性。本发明的实施方式特别适用于那些核心操作系统镜像存储在 NAND Flash 或其他类型的非执行非易失性存储器中,并且在启动时将该镜像复制到 RAM 的设备。本发明的优选实施方式包括识别核心 OS 镜像中未使用的功能,将其从发现的可执行文件中移除,用存根替换它们以确保剩余功能的二进制兼容性,并使用这些受影响可执行文件的“微小变体”构建一个修订后的核心 OS 镜像。然后,包含被移除功能的完整版本的可执行文件版本被作为单独的可加载模块放置在存储器中,以供可能需要它们的售后市场应用程序使用。
  • [0041]
    Embodiments of the invention can enable the XIP or RAM memory overhead of a computing device to be reduced in direct proportion to reduction in feature sets, while at the same time permitting compatibility between all members of a product family irrespective of the features they offer.
    本发明的实施方式可以使计算设备的 XIP 或 RAM 内存开销与功能集的减少成正比降低,同时允许产品系列的所有成员之间保持兼容性,无论它们提供哪些功能。
  • [0042]
    An exemplary implementation of the invention will now be described in detail with reference to the accompanying drawings, in which:
    现在将结合附图详细描述本发明的示例实施方式,其中:
  • [0043]
    FIG. 1 illustrates the occurrence of unused functions;
    图 1 说明了未使用函数的发生;
  • [0044]
    FIG. 2 represents an exemplary implementation of the invention; and
    图 2 表示本发明的示例性实施方式;和
  • [0045]
    FIG. 3 is a flow chart illustrating a process for modifying software.
    图 3 是一个说明修改软件流程的流程图。
  • [0046]
    The preferred embodiment of the invention may advantageously be applied to reduce XIP or RAM memory on devices which provide their core operating system together with other (non-core) executables in NAND Flash storage memory. In such an arrangement, the core image contains executable files together with all their dependencies and is recursively copied from NAND Flash to RAM at boot. This core image is supplied as a single file on NAND Flash; when the image is copied into RAM, it then appears as multiple files in a conventional XIP read-only file system (ROFS). The remainder of the non-core executables remain in the non-XIP ROFS on NAND Flash and are loaded and unloaded on demand; unlike the contents of the core image, they do not have to occupy reserved sections of memory, and any resources they consume can be freed when they are no longer required.
    本发明的优选实施方式可以有效地应用于减少在提供其核心操作系统以及其他(非核心)可执行文件在 NAND Flash 存储内存中的设备上的 XIP 或 RAM 内存。在这种安排中,核心镜像包含可执行文件及其所有依赖项,并在启动时从 NAND Flash 递归地复制到 RAM。该核心镜像作为单个文件在 NAND Flash 上提供;当镜像复制到 RAM 时,它以传统 XIP 只读文件系统(ROFS)中的多个文件的形式出现。非核心可执行文件的其他部分仍保留在 NAND Flash 上的非 XIP ROFS 中,并根据需要加载和卸载;与核心镜像的内容不同,它们不必占用保留的内存区域,并且当不再需要时,它们消耗的任何资源都可以被释放。
  • [0047]
    As described above, provision of a fully-featured version of the core OS on a device with only a reduced feature set would inevitably allocate valuable and scarce XIP memory at boot time for a significant number of functions that are not needed by the rest of the core OS. Furthermore, because the entire core is statically linked, it is impractical for the RAM so allocated to be freed up for other purposes.
    如上所述,在仅具有缩减功能集的设备上提供完整功能的内核操作系统版本,不可避免地会在启动时为大量对其余内核操作系统不需要的功能分配宝贵的、稀缺的 XIP 内存。此外,由于整个内核是静态链接的,因此为其他目的释放所分配的 RAM 是不切实际的。
  • [0048]
    In accordance with the preferred embodiment of the invention, when a function in an executable file is identified as not being used in the particular version of the OS, it is stubbed for that version: any subroutines which depend on the unused function and are also unused are removed from the OS code, so that what remains is an executable file of reduced size that includes only a void function. A void function is one that does not run, and therefore does not perform any tasks.
    根据本发明优选实施方式,当可执行文件中的某个功能被识别为在特定版本的操作系统中未被使用时,该功能会为此版本创建 stub:任何依赖于未使用功能的子程序如果也是未使用的,则从操作系统代码中移除,以便剩余的是一个包含只有空函数的、尺寸缩减的可执行文件。空函数是不会运行的函数,因此不会执行任何任务。
  • [0049]
    For example, if a function previously appeared in the executable file as:
    例如,如果某个函数先前出现在可执行文件中为:
  • void func1( )
    {
    func2( )
    func3( )
    func4( )
    }

    then after stubbing it would appear as:
    然后,在将其存根化后,它将显示为:
  • void func1( )
    {
    }
  • [0050]
    The stubbed function is empty: it contains no working code, and it now requires less memory space.
    被替换的函数是空的:它不包含任何可执行代码,现在需要的内存空间更少。
  • [0051]
    It should be noted that unused functionality may be identified and removed from code in accordance with the invention when the code is in human-readable or in computer-readable form. In most implementations it is likely to be preferable to identify and remove the functions from source code because in this form the code is more easily readable by an engineer for verification. However, tools could be developed for removing the functions once code has been compiled.
    应当注意的是,根据本发明,当代码以人类可读或计算机可读形式存在时,可识别并从代码中移除未使用功能。在大多数实现中,更优选从源代码中识别并移除函数,因为以这种形式代码更易于由工程师进行验证。然而,一旦代码被编译,也可以开发工具来移除这些函数。
  • [0052]
    FIG. 1 illustrates the concept of unused functions by way of example. It shows a number of files within a core OS. An executable file “.exe” is shown to call a function fA from a dynamic link library, DLL1. A DLL is a type of executable file which typically contains a number of functions that can be used by functions in other executable files or other DLLs. fA is known as an exported function, since it may be invoked by means of a call from a function in a different executable file or DLL. When fA is called by the .exe file, DLL1 is loaded into RAM and fA executes, and it in turn calls a further function fB that is held in DLL2. DLL2 is then loaded and fB executed.
    图 1 通过示例说明了未使用函数的概念。它显示了核心操作系统中的多个文件。一个可执行文件“.exe”被显示为从动态链接库 DLL 1 调用函数 f A 。DLL 是一种可执行文件类型,通常包含多个可被其他可执行文件或其他 DLL 中的函数使用的函数。f A 被称为导出函数,因为它可以通过来自不同可执行文件或 DLL 中的函数的调用而被调用。当 f A 被.exe 文件调用时,DLL 1 被加载到 RAM 中,f A 执行,并反过来调用保存在 DLL 2 中的另一个函数 f B 。然后加载 DLL 2 并执行 f B
  • [0053]
    As can be seen from FIG. 1, DLL1 and DLL2 each contain a number of functions—example functions fC, fD and fE are shown explicitly. FIG. 1 also shows schematically that fC, when executed, will call fD from DLL2. However, suppose that no executable files in the version of the core OS of the present example ever invoke fC fC will therefore never run, and is an example of a function that represents wasted memory usage. The same is true in this example for fD, which can only be called by fC, and will therefore not be used in this core OS image version. A further function fE in this example is held in DLL2, and is not invoked by any executable functions in this version of the core OS image. fE therefore also represents wasted memory usage.
    从图 1 可以看出,DLL 1 和 DLL 2 各包含多个函数——示例函数 f C 、f D 和 f E 被明确展示。图 1 还示意性地表明,当 f C 执行时,会调用 DLL 2 中的 f D 。然而,假设在当前示例的核心操作系统版本中没有任何可执行文件调用 f C ,那么 f C 将永远不会运行,是一个代表内存使用浪费的函数示例。在这个示例中,f D 也同样如此,它只能被 f C 调用,因此在核心操作系统映像的这个版本中不会被使用。在这个示例中,另一个函数 f E 存放在 DLL 2 中,并且在这个核心操作系统映像版本中没有任何可执行函数调用它。因此,f E 也代表内存使用浪费。
  • [0054]
    The skilled person will be aware of various means by which unused function could be identified. Examples are linker feedback and caligraph analysis. However, linker feedback has been found by the present inventors to provide more reliable results, and is therefore the preferred technique. The armlink command, described in the RealView® Compilation Tools Linker and Utilities Guide Version 3.0 (http://www.arm.com/pdfs/DUI0206G_rvct_linker_and_utilities_quide.pdf, especially in sections 3.3.3 to 3.3.5, is an example of a tool that may be used to identify unused functions.
    熟练人员会知道识别未使用函数的各种方法。例如链接器反馈和字形分析。然而,本发明人发现链接器反馈能提供更可靠的结果,因此是首选技术。armlink 命令,如 RealView®编译工具链接器和实用工具指南版本 3.0(http://www.arm.com/pdfs/DUI0206G_rvct_linker_and_utilities_quide.pdf,特别是在第 3.3.3 至 3.3.5 节中描述,是一个可用于识别未使用函数的工具示例。
  • [0055]
    There are various reasons why functions in the original version of the core OS image are unused. These include:
    原始核心操作系统映像中的函数未使用的原因有多种。包括:
      • 1) They may support the use of hardware which is not present on all versions of the devices on which the OS is intended to be used. For example, the generic (original) OS may cater for the possible use of an SD card, whereas some devices on which the OS is implemented use no memory card, a Compact Flash card, or a USB-compatible memory stick. In such devices, the particular functionality provided for compatibility with an SD card is not required, and could therefore be removed.
        1)它们可能支持在操作系统预期使用的所有设备版本上都不存在的硬件。例如,通用(原始)操作系统可能支持 SD 卡的潜在使用,而一些实现该操作系统的设备则不使用内存卡、紧凑型闪存卡或 USB 兼容的存储棒。在这些设备中,为与 SD 卡兼容而提供的特定功能是不必要的,因此可以删除。
      • 2) They may relate to the use of an application that needs to be separately downloaded in order to operate on a device, but the application requires hardware that is not provided in certain devices. So, for example, an email messaging application that can be downloaded for use on certain devices may require the presence of a particular type of processor which may not be provided on all devices for which the generic OS is intended. Thus, the functions that would provide the email messaging capability will be unused on versions of the OS that are to be used on devices without the relevant processing capacity.
        2) 它们可能与需要单独下载才能在设备上运行的应用程序有关,但该应用程序需要某些设备上未提供的硬件。例如,一个可在某些设备上下载使用的电子邮件消息应用程序可能需要特定类型的处理器,而这种处理器可能并非所有通用操作系统所针对的设备都提供。因此,在用于不具备相关处理能力的设备上的操作系统版本中,提供电子邮件消息功能的功能将不会被使用。
  • [0058]
    In addition, functions may be identified as “unused” when they are likely to be used only on an occasional basis, or used only by functions outside the core OS. This is an important aspect of the preferred embodiment of the invention, since in such cases it can be inefficient to have to load the functions as part of the core OS when they are not necessarily required for use.
    此外,当功能可能仅在偶尔使用,或仅由核心操作系统外的功能使用时,它们可能被识别为“未使用”。这是本发明优选实施方式的一个重要方面,因为在这些情况下,当它们并非必然需要使用时,将作为核心操作系统的一部分加载这些功能可能效率低下。
  • [0059]
    It can be seen from FIG. 1, and from the corresponding part of the description above, that memory savings could be made if fC, fD and fE could be removed from the OS image. While it would be possible to simply delete any reference to these functions from the OS, the preferred embodiment of the invention instead involves retaining a skeletal version, or stub, of the function. Where an unused function is identified, the executable retains a reference to the primary function (such as fC). However the contents of that function, including the unused functions which would have been called by the primary function, are removed from the executable, thereby leaving the following form of function:
    从图 1 和上述描述的相关部分可以看出,如果能够从操作系统映像中移除 f C 、f D 和 f E ,则可以节省内存。虽然可以简单地从操作系统中删除对这些函数的任何引用,但发明的优选实施方式涉及保留函数的骨架版本或 stub。当识别到未使用的函数时,可执行文件保留对主函数(例如 f C )的引用。然而,该函数的内容,包括主函数可能调用的未使用函数,都从可执行文件中移除,从而留下以下形式的函数:
  • void func1( )
    {
    }
  • [0060]
    As an alternative to leaving a remnant of the original function, the function could be removed altogether and replaced with a marker indicating that the function is absent from the executable. Both of these alternatives are intended to be encompassed by the term “void functions” as used herein, which indicates the presence of an item of code having content which is inoperative or not fully operative, and which therefore is incapable of performing the computing tasks represented by the corresponding original function.
    作为保留原始函数残留物的替代方案,该函数可以被完全移除,并用一个标记来代替,该标记表明该函数在可执行文件中不存在。这两种替代方案均旨在被此处使用的“void 函数”术语所涵盖,该术语表示存在一个代码项,其内容处于非运行状态或未完全运行状态,因此无法执行由相应原始函数所代表的计算任务。
  • [0061]
    Ordinal number linking is utilised in the preferred embodiment: ordinal numbers, which are assigned to functions in an exported set (such as a DLL) indicate the position of one function relative to another function in a defined order. Ordinal numbers are the index by which functions are linked to in the preferred embodiment, so that a function calling another function will refer to the ordinal number of the other function (rather than, say, its name or its location in physical memory) in order to invoke it. In this embodiment, retaining a reference in a stub to a primary function has the advantage that binary compatibility with other members of a family may be retained, as discussed in detail below.
    序号链接在优选实施方式中被采用:分配给导出集(例如 DLL)中的函数的序号,表示在一个定义好的顺序中一个函数相对于另一个函数的位置。序号是优选实施方式中函数链接的索引,因此一个调用另一个函数的函数会通过序号来引用该函数(而不是,比如说,它的名称或它在物理内存中的位置)以调用它。在这种实施方式中,在 stub 中保留对主函数的引用具有优势,可以保持与家族中其他成员的二进制兼容性,如下面详细讨论的。
  • [0062]
    If a function having a particular ordinal number is unused and is thus a candidate for deletion, it is desirable to retain a stub of that function rather than deleting any reference to the function, so that the relative positions of all other functions in the same set do not shift within the predefined order. For example, simply deleting a function at ordinal number 9 may have the effect that functions at ordinal numbers 10 onwards assume new ordinal numbers 9 onwards, since the previous function 9 no longer exists in the order. This could be undesirable because the ordinal numbers of this version of code would no longer be compatible with other versions of the OS that retain the original ordinal numbering, and updates of the code may therefore need to be customised to the new numbering scheme. If many different forms of the OS were to exist for this reason, then there would be obvious impacts on the cost and viability of future improvements or additions to the OS.
    如果一个具有特定序号的函数未被使用且因此成为删除候选,则最好保留该函数的 stub,而不是删除对该函数的任何引用,以便同一集中的所有其他函数的相对位置在预定义的顺序中不发生偏移。例如,仅删除序号为 9 的函数可能会造成序号为 10 及以后的函数依次采用新的序号 9 及以后,因为原有的序号 9 不再存在于顺序中。这可能是不理想的,因为该代码版本的序号将不再与其他保留原始序号编号的操作系统版本兼容,因此代码的更新可能需要针对新的编号方案进行定制。如果由于这个原因存在许多不同形式的操作系统,那么未来对操作系统进行改进或添加的功能的成本和可行性将受到明显影响。
  • [0063]
    Instead, it is preferred to retain a stub at the ordinal position of the unused function, in the manner illustrated above. In this way, the contents of the function are removed, but the function still exists in an empty form in the OS, thereby retaining its ordinal number so that binary compatibility with core OSs of other family members can be ensured, and extra functionality relying on the presence of the function previously at that ordinal number can be more easily added on.
    相反,更优选的方式是在未使用的函数的序号位置保留一个 stub,如上所述。这样,函数的内容被移除,但该函数仍以空形式存在于操作系统中,从而保留其序号,以确保与该系列其他成员的核心操作系统的二进制兼容性,并且可以更轻松地添加依赖于先前在该序号位置存在的函数的额外功能。
  • [0064]
    In general, a given part of a set of code, that is intended for a specific end use but that will not necessarily be used in all implementations, is known as a variant. In the present description, the term variant is also used to refer to alternative versions of a particular piece of code, such as a DLL. In this description, executables that are provided only for certain end use cases but are unrequired in a particular implementation are referred to as tiny variants after they have been stubbed. The tiny variants have minimal function stubs, which replace the body of those functions that are not required for a reduced feature set. The tiny variants need not contain any operative code, that is they need not be capable of performing any computing tasks: they are simply used to replace the original full-featured components while maintaining the ordinal number of the original component.
    一般来说,一组代码中某个特定用途的部分,虽然设计用于特定用途,但并不一定会被所有实现使用,被称为变体。在本描述中,术语变体也用于指代特定代码片段的替代版本,例如 DLL。在本描述中,仅用于特定用例但特定实现中不需要的可执行文件,在经过 stub 处理后被称为微小变体。微小变体具有最小的函数 stub,这些 stub 替换了那些对于减少功能集来说不需要的函数的主体。微小变体不需要包含任何操作代码,也就是说它们不需要能够执行任何计算任务:它们只是用来替换原始的完整功能组件,同时保持原始组件的序号。
  • [0065]
    Tiny variants may be created from any executable code components, including Dynamic Link Libraries (DLLs) and stand alone executables (EXEs). Because they are part of the core OS, these tiny variants are copied at boot time into XIP RAM instead of the fully featured variants. The originals (the full variants) of the DLLs and EXEs containing the selected components can then be provided as loadable executable program files in storage memory instead of as part of the core OS image; this is described in more detail below.
    可以从任何可执行代码组件创建微小的变体,包括动态链接库(DLL)和独立可执行文件(EXE)。由于它们是核心操作系统的一部分,这些微小变体在启动时被复制到 XIP RAM 中,而不是完整功能的变体。然后,包含所选组件的 DLL 和 EXE 的原始版本(完整变体)可以作为可加载的可执行程序文件提供在存储内存中,而不是作为核心操作系统映像的一部分;这将在下面详细描述。
  • [0066]
    In the preferred embodiment binary compatibility between different core OS images is supported by means of rules governing the circumstances under which components loadable from storage memory can be used to replace components from a particular OS core image.
    在优选实施方式中,通过管理可从存储内存加载的组件在何种情况下可以用来替换特定操作系统核心映像中的组件的规则,来支持不同核心操作系统映像之间的二进制兼容性。
  • [0067]
    To illustrate these rules, suppose that executable FRED.EXE in the core OS image uses a DLL called JOE.DLL. The two will be statically linked when the core OS image is built. If you wish to modify JOE.DLL, then the modified version can be placed in memory storage; however, FRED.EXE still uses the original version from the core OS image, as they are statically linked. If, however, you add a new version of FRED.EXE in memory storage then it can now use the new version of JOE.DLL also in memory storage. Only those applications in the core OS image that were statically linked to it continue to use the version of JOE.DLL included in the image.
    为了说明这些规则,假设核心操作系统镜像中的可执行文件 FRED.EXE 使用了一个名为 JOE.DLL 的动态链接库。这两者在核心操作系统镜像构建时会进行静态链接。如果你希望修改 JOE.DLL,那么修改后的版本可以放置在内存存储中;然而,FRED.EXE 仍然使用核心操作系统镜像中的原始版本,因为它们是静态链接的。但是,如果你在内存存储中添加了 FRED.EXE 的新版本,那么它现在也可以使用内存存储中的 JOE.DLL 的新版本。只有那些与核心操作系统镜像静态链接的应用程序会继续使用镜像中包含的 JOE.DLL 版本。
  • [0068]
    The application of these rules means that the provision of executables as separate files in storage memory which include the full versions of anything provided as a tiny variant in the core OS image allows any after-market executable loaded on to the device to function as intended; instead of linking to a DLL with tiny variants from the core OS image, such an executable would dynamically link and load the full version of the DLL provided in storage memory.
    应用这些规则意味着将可执行文件作为单独的文件存储在存储内存中,这些文件包含核心操作系统镜像中提供的完整版本的小型变体,允许任何在设备上加载的后市场可执行文件按预期运行;这种可执行文件不会链接到核心操作系统镜像中的小型变体 DLL,而是会动态链接并加载存储内存中提供的完整 DLL 版本。
  • [0069]
    Taking advantage of these rules, the preferred embodiment of this invention further utilises the following mechanism for producing a core OS image that is compatible with other core OS images in the same family:
    利用这些规则,本发明的优选实施例进一步采用以下机制来生成与同一系列中的其他核心操作系统镜像兼容的核心操作系统镜像:
      • 1. create a full core OS image as a test image
        1. 将完整的核心操作系统镜像作为测试镜像创建
      • 2. find all statically unused exported functions in the executables within that test core and stub all those unused exported functions in the source code
        2. 在该测试核心中的可执行文件中查找所有静态未使用的导出函数,并在源代码中 stub 所有这些未使用的导出函数
      • 3. find all statically unused unexported functions in the executables within that test core and delete all those unused unexported functions in the source code
        3. 在该测试核心中的可执行文件中查找所有静态未使用的未导出函数,并在源代码中删除所有这些未使用的未导出函数
      • 4. identify and remove from the source code any executables no longer needed
        4. 识别并从源代码中移除不再需要的可执行文件
      • 5. build the core image containing only the used functions
        5. 构建仅包含已使用函数的核心镜像
      • 6. identify all executables which have been produced as tiny variants by steps 2 and 3
        6. 识别所有通过步骤 2 和 3 产生的微小变体可执行文件
      • 7. build full variants for all executables identified in step 6 together with copies of all executables identified and removed in step 4, and include them in storage memory.
        7. 为步骤 6 中识别的所有可执行文件构建完整变体,并包含步骤 4 中识别和移除的所有可执行文件的副本,将它们存入存储内存。
      • 8. recursively remove any DLLs now not needed in the core due to the reduced dependencies of the new core functionality, and include them in storage memory.
        8. 递归地移除因新核心功能依赖减少而在核心中不再需要的任何 DLL,并将它们包含在存储内存中。
  • [0078]
    This method is shown diagrammatically in FIG. 3. The mechanism provides the ability to build core OS images which minimise the amount of XIP memory that needs to be used in each device that is a member of a product family. Components in the core OS image continue to use the reduced variants also found in the core, as they are statically linked at build time to those variants.
    该方法如图 3 所示。该机制提供了构建核心操作系统镜像的能力,这些镜像可最小化产品系列中每个设备需要使用的 XIP 内存量。核心操作系统镜像中的组件继续使用在核心中也发现的减少变体,因为它们在构建时被静态链接到这些变体。
  • [0079]
    If the core OS variant is also held in storage memory it will link to the variant found in storage memory.
    如果核心操作系统变体也存储在存储内存中,它将链接到存储内存中找到的变体。
  • [0080]
    Other components in storage memory, and any application installed post-manufacture, will link to the full variants, satisfying any compatibility requirements.
    存储内存中的其他组件,以及制造后安装的任何应用程序,将链接到完整变体,以满足任何兼容性要求。
  • [0081]
    If usage at boot-time of functions in the core image is X % (in terms of the number of bytes) of a full executable tree, then the XIP usage at boot would decrease by (100−X) % at the expense of extra storage memory usage of X % (due to the duplication).
    如果核心镜像中函数在启动时的使用量是完整可执行树中字节数的 X%,那么在启动时 XIP 的使用量将减少(100-X)%,但需要额外使用 X%的存储内存(由于重复)。
  • [0082]
    For an executable with a tiny variant in core and a full variant in storage memory, where of the tiny variant is Y % of the full variant, (100+Y) % of the full variant's size will be used up in XIP usage by the executable whenever the full variant needs to be loaded. However, the XIP memory consumed by the full variant will be freed when it is no longer needed, and given the larger number of full variants that no longer consume any XIP memory, the overall tradeoff is beneficial.
    对于一个在核心中有微小变体而在存储内存中有完整变体的可执行文件,其中微小变体是完整变体的 Y%,每当需要加载完整变体时,可执行文件在 XIP 使用中会使用完整变体大小的(100+Y)%。然而,当完整变体不再需要时,它所消耗的 XIP 内存将被释放,并且由于不再消耗任何 XIP 内存的完整变体数量更多,整体权衡是有益的。
  • [0083]
    A further optimisation of the method described here is not to provide a full variant of an executable in storage memory, but to provide instead a variant that only contains the full version of those functions that are stubbed out in the tiny variant provided in the core. Those functions that are provided in full in the core are stubbed out in the variant provided in storage memory. When a client using the storage variant calls a function only contained in the core, the stub in the storage variant would then forward it to the core variant's function.
    这里描述的方法的进一步优化不是在存储内存中提供可执行文件的完整变体,而是在核心提供的微小变体中仅包含被 stub 掉的函数的完整版本。核心中提供的完整函数在存储内存中提供的变体中被 stub 掉。当使用存储变体的客户端调用仅在核心中包含的函数时,存储变体中的 stub 会将其转发到核心变体的函数。
  • [0084]
    In other words, the tiny variant and the variant in storage memory complement each other. We shall refer to the variant in storage memory as the complemented variant. Neither variant individually provides a full version of the functions in the original executable, but they do when taken together; every function is fully provided in either the tiny variant in the core OS image or the complemented variant in storage memory, but no functions are provided in both.
    换句话说,微小变体和存储内存中的变体相互补充。我们将存储内存中的变体称为补充变体。这两个变体单独都不提供原始可执行文件中函数的完整版本,但它们结合起来提供;每个函数要么在核心操作系统映像中的微小变体中完整提供,要么在存储内存中的补充变体中完整提供,但不会在两者中都提供。
  • [0085]
    In the preferred embodiment the addresses of functions and methods provided in full in the tiny variant of an executable present in the core OS image are inserted into the export table of the variant of that executable provided in storage memory before that executable is placed in storage memory. The header of the executable provided in storage memory is modified before that executable is placed in storage memory to indicate where entries in the export table reference addresses of functions and methods provided in full in the tiny variant of that executable present in the core OS image, and the loader of that executable inspects its header and uses such indications to avoid further modifying the said entries in the export table.
    在优选实施方式中,核心操作系统镜像中存在于可执行文件的微型变体中提供的函数和方法地址被插入到存储内存中该可执行文件变体的导出表中,该可执行文件被放置到存储内存之前。在可执行文件被放置到存储内存之前,对存储内存中的可执行文件头进行修改,以指示导出表中的条目引用核心操作系统镜像中存在于该可执行文件微型变体中提供的完整函数和方法地址,并且该可执行文件的加载器检查其头信息,并使用这些指示来避免进一步修改导出表中的所述条目。
  • [0086]
    Preferably, linkage involving elements of the core OS is managed statically and linkage involving modules present as separately loadable entities in storage memory is managed dynamically.
    优选地,核心操作系统的元素之间的链接是静态管理的,而存储内存中以可单独加载实体形式存在的模块之间的链接是动态管理的。
  • [0087]
    The use of complemented variants can ensure that no code is unnecessarily duplicated and therefore saves memory. We now discuss in more detail how this optimisation can be implemented.
    使用补码变体可以确保不会不必要地重复代码,从而节省内存。我们现在将更详细地讨论如何实现这种优化。
  • [0088]
    As described earlier, all executables in the core OS image are statically linked to the tiny variant. There is no need for any calls made by these executables to the tiny variant to be forwarded to the complemented variant, since the whole point of having a tiny variant is that it completely satisfies the requirement of the executables in the core OS image. Executables in storage memory, however, will link to any complemented variant which is also present in storage memory. These variants need to be able to forward calls made to them on to the tiny variant in the core OS image for all functions which they do not fully implement themselves.
    如前所述,核心操作系统映像中的所有可执行文件都静态链接到小型变体。由于小型变体的存在目的就是完全满足核心操作系统映像中可执行文件的需求,因此这些可执行文件对小型变体的任何调用都不需要转发到补码变体。然而,存储内存中的可执行文件将链接到存储内存中也存在的任何补码变体。这些变体需要能够将所有它们未完全实现的函数对它们的调用转发到核心操作系统映像中的小型变体。
  • [0089]
    As an example case, we shall consider an original fully featured DLL named X which is further identified by a conventional version number in major version/minor version form. This DLLX [Major/minor version] provides methods f1( ), f2( ) and f3( ), and is shown in FIG. 2.
    作为一个例子,我们将考虑一个名为 X 的原始完整功能的 DLL,它通过主版本号/次版本号形式的传统版本号进一步标识。这个 DLLX [主版本号/次版本号] 提供了方法 f1( )、f2( ) 和 f3( ),如图 2 所示。
  • [0090]
    In order to reduce the size of the core image and the consequent impact on system RAM usage, this executable is split into two: DLLX [Major/minor+1 version] is the tiny variant provided within the core image and DLLX[Major/minor+2 version] is the complemented variant provided in storage memory (“ROFS”).
    为了减小核心镜像的大小以及随之对系统 RAM 使用的 影响,这个可执行文件被分成两部分:DLLX [主版本号/次版本号+1 版本] 是在核心镜像中提供的微小变体,而 DLLX[主版本号/次版本号+2 版本] 是在存储内存(“ROFS”)中提供的补充变体。
  • [0091]
    The tiny variant contains an implementation only of method f1( ), as it is the only method utilized by the other modules in the core, which are linked to it statically. The unused methods f2( ) and f3( ) in this variant are stubbed and marked as ABSENT.
    这个微小变体只包含方法 f1()的实现,因为它是由核心中静态链接到它的其他模块唯一使用的方法。这个变体中未使用的方法 f2()和 f3()被 stub 处理并标记为 ABSENT。
  • [0092]
    The complemented variant contains implementations of methods f2( ) and f3( ). Method f1( ) in this variant is stubbed and marked as ABSENT. The addresses of all the methods provided in this variant are made public in a table of exported functions; these are in turn picked up by the loader of any executable modules that depend on DLLX. The loader functions as a dynamic linker and fixes up any references to the methods in DLLX to point to the correct addresses.
    这个补全变体包含方法 f2()和 f3()的实现。这个变体中的方法 f1()被 stub 处理并标记为 ABSENT。这个变体中提供的所有方法的地址在导出函数表中公开;这些地址随后被依赖 DLLX 的任何可执行模块的加载器获取。加载器充当动态链接器,并修复对 DLLX 中方法的任何引用,使其指向正确的地址。
  • [0093]
    For the optimisation to work, the dynamic linking with the complemented variant has to work in such a way as to ensure that references to f2( ) and f3( ) are fixed up in the normal way, but that references to f1( ) are fixed up with the address of the method in the tiny variant.
    为了让优化生效,动态链接必须以这样的方式工作:确保对 f2()和 f3()的引用按常规方式修正,但对 f1()的引用则以微变体中方法的地址修正。
  • [0094]
    The exact method that is used to do this may be varied for use with different operating systems, but the basic principles are as described above. A specific implementation will now be described with reference to the Symbian OS advanced operating system for mobile wireless devices. It should be noted that this implementation is described only for the purposes of illustration of the general principles and is not intended to limit the scope of the invention in any way. For example, those skilled in the art will appreciate that the principles set out above can be applied to any operating system which includes a run-time program loader that inspects executable file headers.
    具体使用这种方法的方式可以根据不同的操作系统而有所不同,但基本原理如上所述。现在将以移动无线设备的高级操作系统 Symbian OS 为例,描述一个具体的实现方法。需要注意的是,这种实现方法仅用于说明基本原理,并不意在以任何方式限制发明的范围。例如,本领域技术人员会理解,上述原理可以应用于任何包含运行时程序加载器且该加载器检查可执行文件头的操作系统。
  • [0095]
    The workings of program loading and dynamic run-time linking in Symbian OS are described in the Chapter 10 of ‘Symbian OS Internals’ edited by Jane Sales, published by Wiley in 2005, ISBN 0-470-02524-7. A Symbian OS executable includes a pointer to an .edata table at offset 0x58 in the executable file header. This is a table containing the export directory:
    在《Symbian OS Internals》一书的第 10 章中,由 Jane Sales 编辑、Wiley 出版社于 2005 年出版(ISBN 0-470-02524-7)详细描述了 Symbian OS 的程序加载和动态运行时链接的工作原理。Symbian OS 的可执行文件在文件头偏移 0x58 处包含一个指向.edata 表的指针。这是一个包含导出目录的表:
      • “The export directory is a table supplying the address of each function exported from this executable. Each entry holds the start address of the function as an offset relative to the start of the code section:
        “导出目录是一个表,它提供了从该可执行文件导出的每个函数的地址。每个条目以相对于代码段起始地址的偏移量形式存储函数的起始地址:
  • 00
    Address of 1st function exported from this executable.
    从该可执行文件导出的第一个函数的地址。
    04
    Address of 2nd function exported from this executable.
    从该可执行文件导出的第二个函数的地址。
    ...
    4n-4
    Address of last function exported from this executable.
    从该可执行文件导出的最后一个函数的地址。
      • The order of exports in the table corresponds to the order in the DEF file for this executable. The table is not null terminated. Instead, the number of entries in the table is available from the file's image header.” ibid. p. 388
        表中导出的顺序与该可执行文件的 DEF 文件中的顺序相对应。该表不是以空字符结尾的。相反,表中的条目数可以从文件映像头中获取。” ibid. p. 388
  • [0098]
    In the case of the complemented variant, the .edata table needs to ensure that the entry for f1( ) is actually populated with the address of the implementation in the code section. This is done at the time the embedded software (commonly called the ROM) for the device is built. It will be recalled that the ROM includes both a core OS image, which will include all tiny variants, and a number of non-core files in a read-only file system (ROFS) which will include all complemented variants. A redirect tool is provided with information on f1( ) which is used to construct an export table for the complemented variant that delegates its implementation to the tiny variant.
    在补充变体的情况下,.edata 表需要确保 f1()的条目实际填充了代码段中实现的地址。这通常在构建设备嵌入式软件(通常称为 ROM)时完成。需要回忆的是,ROM 包含一个核心操作系统镜像,其中将包括所有微小变体,以及一个只读文件系统(ROFS)中的多个非核心文件,该文件系统将包括所有补充变体。提供了一种包含 f1()信息的重定向工具,用于构建补充变体的导出表,该表将其实现委托给微小变体。
  • [0099]
    This redirect tool, during the ROM build, picks up the absolute address of f1( ) in the core OS image. Before the non-core ROFS portion of the ROM is built, the tool fixes the .edata table in the complemented variant provided in ROFS with the address for f1( ) retrieved from the core OS image.
    这个重定向工具在 ROM 构建过程中,获取核心操作系统镜像中 f1()的绝对地址。在 ROM 的非核心 ROFS 部分构建之前,该工具使用从核心操作系统镜像中获取的 f1()地址,修正 ROFS 中提供的补充变体中的.edata 表。
  • [0100]
    However, the address for f1( ) so inserted is an absolute address, while the normal addresses for f2( ) and f3( ) in the export table are, by necessity, relative addresses. This is because no dynamically loaded executable knows in advance where in memory it is going to be loaded; so any addresses for exported functions have to be given relative to the beginning of the executable. One of the jobs of the loader is to fix up the export table to ensure that all entries point at the correct absolute address.
    然而,插入的 f1( )地址是一个绝对地址,而导出表中的 f2( )和 f3( )的正常地址,出于必要,是相对地址。这是因为没有动态加载的可执行文件能预先知道它将被加载到内存的哪个位置;因此,所有导出函数的地址都必须相对于可执行文件的起始位置给出。加载器的一项任务就是修正导出表,以确保所有条目都指向正确的绝对地址。
  • [0101]
    The loader therefore has to be told that while it is quite welcome to fix up the addresses of f2( ) and f3( ) in the usual way, the address of f1( ) should be left alone, as it is already absolute.
    因此,加载器必须被告知,虽然它很乐意以常规方式修正 f2( )和 f3( )的地址,但 f1( )的地址应该保持原样,因为它已经是绝对地址了。
  • [0102]
    In Symbian OS, this is done by means of an extension to the executable file header (the E32ImageHeader described in Appendix 2 of ‘Symbian OS Internals’. A new “redirect-to-rom” bitmap is added to the module V-header and the redirect tool sets the corresponding bit in the bitmap in order to indicate to the loader that the address of a particular ordinal in the export table is fixed.
    在 Symbian 操作系统中,这是通过扩展可执行文件头(在《Symbian 操作系统内部》附录 2 中描述的 E32ImageHeader)来完成的。在模块 V 头中添加了一个新的“redirect-to-rom”位图,重定向工具在该位图中设置相应的位,以指示加载器导出表中的特定序号的地址是固定的。
  • [0103]
    The loader is also modified to examine the “redirect-to-rom” bitmap during the loading of the complemented variant, and it does not fix up the address of any entry in the export table if the entry in the bitmap is set.
    加载器也被修改为在加载补充变体时检查“重定向到 ROM”位图,如果位图中的条目被设置,则它不会修复导出表中的任何条目的地址。
  • [0104]
    The effect of this optimisation is shown diagrammatically in FIG. 2. It allows the maximum amount of saving not just of the memory used by the statically linked modules present in the core OS image loaded at boot, but also of the memory used by dynamically linked variant modules provided as separate files in storage memory.
    这种优化的效果如图 2 所示。它不仅允许最大限度地节省静态链接模块占用的内存,这些模块存在于引导时加载的核心操作系统映像中,而且还允许节省动态链接变体模块占用的内存,这些模块作为单独的文件提供在存储内存中。
  • [0105]
    It can be seen from the example described above that the following advantages can result from embodiments of the invention:
    从上述示例可以看出,本发明的一些实施方式可以带来以下优势:
      • The size of an OS core image in a NAND Flash computing device can be reduced in proportion to the feature set provided while retaining binary compatibility with other devices in the same family which are fully featured.
        在 NAND Flash 计算设备中,操作系统核心镜像的大小可以根据所提供的功能集按比例减小,同时仍与其他完全功能化的同系列设备保持二进制兼容性。
      • The smaller size of the core OS image in NAND Flash means that the image consumes less RAM once loaded.
        NAND Flash 中核心操作系统镜像的较小尺寸意味着一旦加载,镜像将消耗更少的 RAM。
      • The smaller size of the core OS image in NAND Flash means that the device will boot up faster.
        NAND Flash 中核心操作系统镜像的更小尺寸意味着设备启动速度更快。
      • The fact that less RAM is required means that devices with a reduced feature set are able to be manufactured at a lower cost.
        所需 RAM 更少意味着功能减少的设备能够以更低的成本制造。
      • The fact that less RAM is required means that a device with a reduced feature set will consume less power.
        所需 RAM 更少意味着功能减少的设备将消耗更少的电力。
      • The complemented variant optimisation of the preferred embodiment extends the memory saving to dynamically loaded variant of modules provided as files in NAND Flash.
        优选实施例的补充变体优化将内存节省扩展到作为文件在 NAND Flash 中提供的动态加载的模块变体。
  • [0112]
    It will be understood by the skilled person that alternative implementations are possible, and that various modifications of the methods and implementations described above may be made within the scope of the invention, as defined by the appended claims.
    本领域技术人员应理解,存在其他可能的实现方式,并且可以在本发明所附权利要求所定义的范围内,对上述方法和实现进行各种修改。

Claims (22)  权利要求 (22)
Hide Dependent   隐藏依赖

1. A method of reducing the size of a set of computer code intended for use in a computing device, the code comprising a plurality of files, each specifying one or more functions for performing computing tasks, the method comprising:
1. 一种减少用于计算设备的一组计算机代码大小的方法,所述代码包括多个文件,每个文件指定一个或多个用于执行计算任务的功能,该方法包括:
identifying functions within the set of code that:
识别代码集合中的函数,这些函数:
i) are available to be called by others of the functions; and
i) 可被集合中的其他函数调用;
ii) will not be called by others of the functions when the files are executed on the computing device; and
ii) 在文件在计算设备上执行时不会被其他函数调用;
removing from the set of code at least part of the content defining the identified functions while retaining, in place of each identified function, a void function of reduced size.
并从代码集合中移除至少部分定义已识别函数的内容,同时保留每个已识别函数的位置,并用一个尺寸更小的空函数替代。
2. A method according to claim 1 wherein the void function contains no operative code.
2. 根据权利要求 1 所述的方法,其中所述空函数不包含可执行代码。
3. A method according to claim 1 wherein each of the identified functions in the set of code is associated with an ordinal number specifying the position of the function within a defined order, and, for each identified function, the step of removing content results in the creation of a void function having the same ordinal number as the identified function.
3. 根据权利要求 1 所述的方法,其中代码集中的每个已识别函数都与一个序号相关联,该序号指定了函数在定义顺序中的位置,并且对于每个已识别函数,删除内容的步骤导致创建一个与已识别函数具有相同序号的空函数。
4. A method according to claim 1 wherein the set of code is an operating system.
4. 根据权利要求 1 所述的方法,其中代码集是操作系统。
5. A method according to claim 1 wherein the set of code is a part of an operating system.
5. 根据权利要求 1 所述的方法,其中代码集是操作系统的一部分。
6. A method according to claim 1 wherein the said identified functions are exported functions.
6. 根据权利要求 1 所述的方法,其中所述已识别的函数是导出函数。
7. A method according to claim 1 further comprising, for at least one of the files containing one or more void functions, creating complementary code for the respective file, the complementary code containing functionality that was removed in the said step of removing at least part of the content, such that a combination of:
7. 根据权利要求 1 所述的方法,进一步包括,对于包含一个或多个空函数的至少一个文件,为相应文件创建补充代码,所述补充代码包含在所述删除至少部分内容步骤中移除的功能,使得组合:
i) the reduced file containing one or more void functions, and
i) 包含一个或多个空函数的减小文件,和
ii) the complementary code,
ii) 补码,
provides functionality equivalent to that of the original file.
提供与原始文件等效的功能。
8. A method according to claim 7 further comprising the step of storing:
8. 根据权利要求 7 所述的方法,进一步包括存储的步骤:
i) the set of code, including the reduced file, and
i) 代码集,包括压缩文件,和
ii) the complementary code
ii) 互补代码
as separately loadable files in storage memory of the computing device in which code cannot execute in place.
作为可单独加载的文件存储在计算设备的存储内存中,其中代码不能就地执行。
9. A method according to claim 8 further comprising providing a linking arrangement configured to link between functions in the reduced set of code and functions in the complementary code, such that all functionality provided by the original set of code can be provided by the combination of the reduced set of code and the complementary code.
9. 根据权利要求 8 所述的方法,进一步包括提供一种链接配置,用于在代码的减少集和互补代码中的函数之间进行链接,以便原始代码集提供的所有功能都可以由减少集和互补代码的组合来提供。
10. A method according to claim 1 further comprising the step of storing:
10. 根据权利要求 1 所述的方法,进一步包括存储的步骤:
i) the reduced set of code, including any void functions, and
i) 减少的代码集,包括任何空函数,和
ii) each file that contains identified functions, in its original form,
ii) 每个包含已识别函数的文件,以其原始形式,
as separately loadable files in storage memory of the computing device in which code cannot execute in place.
作为可单独加载的文件存储在计算设备的存储内存中,其中代码不能就地执行。
11. A method according to claim 10 further comprising a linking arrangement configured to link between functions in the reduced set of code and functions in the said separately loadable files, such that all functionality provided by the original set of code can be provided by the combination of the reduced set of code and the separately loadable files.
11. 根据权利要求 10 所述的方法,进一步包括一个链接装置,配置为在代码的减少集和所述可单独加载的文件中的函数之间进行链接,以便原始代码集提供的功能可以通过减少的代码集和可单独加载的文件的组合来提供。
12. A method according to claim 1 further comprising removing from the set of code any files containing only void functions.
12. 根据权利要求 1 所述的方法,进一步包括从代码集中删除仅包含空函数的任何文件。
13. A method according to claim 12 further comprising storing, in storage memory of the computing device in which code cannot execute in place, and as separately loadable files, the said removed files in the form in which they existed prior to the step of removing content defining the said identified functions.
13. 根据权利要求 12 所述的方法,进一步包括将所述删除的文件以删除内容定义所述识别函数的步骤之前的形式存储在计算设备的存储内存中,并作为可单独加载的文件,其中代码不能原地执行。
14. A method according to claim 1 further comprising the steps of:
14. 根据权利要求 1 所述的方法,进一步包括以下步骤:
identifying further functions within the set of code that:
在代码集中识别其他函数,这些函数:
i) are available to be called by other functions within the same files as the said further functions; and
i) 可供同一文件中的其他函数调用;以及
ii) will not be called by other functions when the files are executed on the computing device; and
ii) 当文件在计算设备上执行时,不会被其他函数调用;以及
removing from the set of code the identified further functions.
从代码集中移除已识别的进一步功能。
15. A set of code intended for use on a computing device, the set of code comprising a plurality of files, each specifying one or more functions for performing computing tasks, wherein those of the functions that:
15. 一套用于在计算设备上使用的代码,该代码集包含多个文件,每个文件指定一个或多个用于执行计算任务的功能,其中那些功能:
i) are available to be called by others of the functions; and
i) 可以被其他函数调用;和
ii) will not be called by others of the functions when the files are executed on the computing device;
ii) 当文件在计算设备上执行时,不会被其他函数调用;
are present in the set of code only as void functions having no operative code.
仅作为没有操作代码的空函数存在于代码集中。
16. A set of code according to claim 15 wherein the void functions represent exported functions.
16. 根据权利要求 15 所述的一组代码,其中空函数表示导出函数。
17. An operating system comprising the set of code according to claim 15.
17. 一种操作系统,包括根据权利要求 15 所述的一组代码。
18. A computing device having non-volatile memory, the memory containing the set of code according to claim 15.
18. 一种计算设备,具有非易失性存储器,该存储器包含根据权利要求 15 所述的一组代码。
19. A computing device according to claim 18 wherein the memory is storage memory in which code cannot execute in place.
19. 根据权利要求 18 所述的计算设备,其中所述内存是存储内存,代码不能就地执行。
20. A computing device according to claim 18 wherein the memory additionally contains, as one or more separately loadable files, complementary code including operative functions, the complementary code being arranged for execution with one or more of the void functions to perform computing tasks.
20. 根据权利要求 18 所述的计算设备,其中所述内存还包含作为一个或多个可单独加载的文件形式的补充代码,包括可操作函数,所述补充代码被安排与一个或多个空函数一起执行以完成计算任务。
21. A computing device according to claim 20 wherein each void function is associated with an ordinal number specifying the position of the function within a defined order, and wherein the complementary code is arranged to be invoked by linking via an ordinal number associated with a void function in the set of code.
21. 一种根据权利要求 20 所述的计算设备,其中每个空函数都与一个序号相关联,该序号指定了函数在定义的顺序中的位置,并且其中补充代码被安排通过链接来调用,该链接通过一组代码中与空函数相关联的序号进行。
22. A computing device according to claim 18 wherein the memory additionally contains, as one or more separately loadable files, operative functions each associated with one of the void functions.
22. 一种根据权利要求 18 所述的计算设备,其中,该内存还包含一个或多个可单独加载的文件,每个可执行函数均与一个空函数相关联。