Linux0.00 ld link Why add-ttext 0

Source: Internet
Author: User

The assembler is traversed two times, some symbol references are marked as relocatable, their offset values are offset values inside the code after compilation, i.e. the value of the LC counter, when loaded into memory run, because the starting load address is indeterminate, Therefore, after loading the code snippet is located in the memory of the starting address to the symbol reference to the original offset, which is called relocation. For example, a JMP ABC will jump to the place where the code snippet is offset by 10, but the code is loaded into memory offset 1000, so the fact that the ABC designator is offset by 10 is 1010 in the actual memory, so the jump to ABC (offset 10) will go wrong. Therefore, the offset of ABC 10 plus the start address 1000 of the load, 1010, so that JMP 1010 is executed correctly, to achieve the purpose of relocation.

Without this option, the default LD will add 0x08048000 to all the offsets in the code, causing many of the 16-bit registers in the HEAD.S code not to open this large number, error. Using-ttext 0 tells the LD to add 0 to all the offsets in the code, which is equivalent to preserving the original value of the symbol reference (that is, the intra-code offset--LC). When the head program is loaded to the memory 0 address run, the real memory reference calculation method is the code original offset +0, but also the original offset, and the symbol reference in the program is still the offset of the original offset, so the memory reference is correct.

For the general assembler in the case of the OS existence of LD link, the default is to add the original offset of the code fragment plus 0x08048000 and then into the elf executable file, because the OS loader loaded elf code to run 0x08048000, rather than 0x0, In this case, the actual memory reference is the original offset +0x08048000, and the symbol reference within the code snippet has actually been changed to the original offset +0x08048000, so the reference is correct.

From this point of view, our hands use-ttext 0 to the code internal symbol reference offset plus 0, and then manually loaded code to run at 0, just to play the role of the loader. Therefore, everything is normal.


This article is from the "mirage1993" blog, make sure to keep this source http://mirage1993.blog.51cto.com/2709744/1570544

Linux0.00 ld link Why add-ttext 0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.