سؤال

OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_ram_entry)
SECTIONS
{
    . = 0xA0008000;

    . = ALIGN(4);
    .text : { *(.text) }

    . = ALIGN(4);
    .rodata : { *(.rodata) }

    . = ALIGN(4);
    .data : { *(.data) }

    . = ALIGN(4);
    .got : { *(.got) }

    . = ALIGN(4);
    .bss : { *(.bss) }
}

I get the output_format, output_arch, entry... maybe meaning that the output will be as elf32-littlearm and so on.

But the Sections part is what I don't get.

this '. =' is the start.

and '. = ALIGN(4)' and .text : { *(.text) } ....

can anybody help me on this T_T

thanks for reading.

هل كانت مفيدة؟

المحلول

Actually, this linker description language is defined in the documentation for ld last I checked. It's not as bad as it looks. Basically, the '.' operator refers to the "current location pointer". So, the line

. = 0xA0008000 

says move the location pointer to that value. The next entry, .text, basically says place all text objects into a .text section in the final ELF file starting at the location pointer (which is also adjusted to have a 4-byte (32-bit) alignment.) Note that the first use of the ALIGN is probably redundant since 0xA0008000 is already 32-bit aligned!

The next sections simply instructs the linker to emit the collection of all .rodata, .data, .got and .bss sections from all input objects into their final respective sections of the ELF binary in order, starting at 32-bit aligned addresses.

So the final ELF binary that the linker produces will have those five sections respectively and sequentially. You can see the structure of that final ELF binary using the readelf utility. It's quite useful and helps to make sense of all of this stuff. Usually there is a cross-version of readelf, something like arm-linux-gnueabi-readelf, or whatever prefix was used to generate the compiler/linker you are using. Start with readelf -S to get a summary of the sections that your ELF file contains. Then you can explore from there. Happy reading!

نصائح أخرى

    . = 0xA0008000;

I think, but I'm not 100% sure, is where the arm will start executing the binary

    . = ALIGN(4);

defines how to align the following instruction.

.text, .data, .rodata, .got and .bss are the sections of the program. text is for instructions, data and rodata for initialized data sections and bss for uninitialized data section. got is global offset table.

    .text : { *(.text) }

This copies all the instructions, similar commands are for data and global offset table.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top