zoukankan      html  css  js  c++  java
  • About Gnu Linker1

    1 OverView

    • ld combines a number of object and archive files, relocates their data and ties up symbol references.
    • This version of ld uses the general purpose BFD libraries to operate on object files. This allows ld to read, combine, and write object files in many different formats.
    • the gnu linker is more helpful in providing diagnostic information. ld continues executing, allowing you to identify other errors.

    2 Linker Command

     

    3 Linker Scripts

    3.1  Basic Linker Script Concepts

    • object file: The linker combines input files into a single output file. The output file and each input file are in a special data format known as an object file format.
    • input section : a section in an input file as an input section.
    • output section : a section in the output file is an output section.
    • contents : Most sections have an associated block of data, known as the section contents.
    • loadable : mean that the contents should be loaded into memory when the output file is run.
    • allocatable : A section with no contents may be allocatable, which means that an area in memory should be set aside, but nothing in particular should be loaded there.
    • neither loadable nor allocatable section: contains some sort of debugging information.
    • VMA: Every loadable or allocatable output section has two addresses. The first is the VMA, or virtual memory address. This is the address the section will have when the output file is run.
    • LMA: The second is the LMA, or load memory address. This is the address at which the section will be loaded.

    3.2 Linker Scripts Formate

    Linker scripts are text files. You write a linker script as a series of commands. Each command is either a keyword, possibly followed by arguments, or an assignment to a symbol.

     

    3.3 Simple Linker Script Example

    3.3.1 SECTIONS command

    describe the memory layout of the output file. Example as below:

    SECTIONS

    {

    . = 0x10000;

    .text : { *(.text) }

    . = 0x8000000;

    .data : { *(.data) }

    .bss : { *(.bss) }

    }

    • The first line sets the value of the special symbol ‘.’, which is the location counter. If you do not specify the address of an output section in some other way, the address is set from the current value of the location counter. The location counter is then incremented by the size of the output section. At the start of the ‘SECTIONS’ command, the location counter has the value ‘0’.
    •  The second line defines an output section, ‘.text’. Within the curly braces after the output section name, you list the names of the input sections which should be placed into this output section.
    • The ‘*’ is a wildcard which matches any file name. The expression ‘*(.text)’ means all ‘.text’ input sections in all input files.

     

    3.4 Simple Linker Script Commands

    3.4.1 Setting the Entry Point

    The first instruction to execute in a program is called the entry point.

    ENTRY(symbol)

    There are several ways to set the entry point.

    _ the ‘-e’ entry command-line option;

    _ the ENTRY(symbol) command in a linker script;

    _ the value of the symbol start, if defined;

    _ the address of the first byte of the ‘.text’ section, if present;

    _ The address 0.

     

    3.4.2 Commands Dealing with Files

    INCLUDE filename - Include the linker script filename at this point.

    INPUT(file, file, ...) - directs the linker to include the named files in the link, as though they were named on the command line.

    GROUP(file, file, ...) - like INPUT, except that the named files should all be archives, and they are searched repeatedly until no new undefined references are created.

     

    3.4.3 Assign alias names to memory regions

    REGION_ALIAS(alias, region)

    The REGION_ALIAS function creates an alias name alias for the memory region region.

     

    3.5 Assigning Values to Symbols

  • 相关阅读:
    【spring 注解驱动开发】spring ioc 原理
    目录大纲,欢迎来戳
    进程相关
    网络编程相关知识点
    Django基本知识
    浅谈 Web框架
    浅谈 Flask 框架
    AJAX小示例
    浅谈cookie 和 session
    ORM:对象关系映射
  • 原文地址:https://www.cnblogs.com/zhizhi25/p/9683633.html
Copyright © 2011-2022 走看看