Linker script syntax
SECTIONS {
...
secname start BLOCK(align) (NOLOAD) : AT ( ldadr )
{ contents } >region :phdr =fill
...
}
explain:
secname : section name
start: starting address: runtime address (runtime addr); relocation address (relocate addr)
AT (ldadr): optional (load addr: load address) If not written, LoadAddr = runtime addr
Contents of { contents }:
start.o //The content is start.o file
* (.text) All code snippet files
start.o * (.text) files
elf file format
1 Link to get the elf file, which contains address information (load addr)
2 Using the loader
:: 2.1 For bare boards, it is the JTAG debugging tool
:: 2.2 For APP, the loader is also APP to parse the elf file and read it into the loading address of the memory
3 Run the program
4 If loadaddr != runtimeaddr the program itself needs to be relocated
The core program should be located at runtimeaddr (relocation addr) or link address when it is running
bin file
1 elf generates bin file
2 Hardware mechanism startup
3 If the location of the bin file is not equal to runtimeaddr, the program itself implements relocation
The bin file/elf file does not save the bss segment. These are global variables with initial values of 0 or not initialized.
When the program is running, the space corresponding to the bss segment is cleared
As an experiment, print out the global variable g_A in hexadecimal
/* 0xABCDEF12 */
void printHex(unsigned int val)
{
int i;
unsigned char arr[8];
/* First take out the value of each bit*/
for (i = 0; i < 8; i++)
{
arr[i] = val & 0xf;
val >>= 4; /* arr[0] = 2, arr[1] = 1, arr[2] = 0xF */
}
/* Print*/
puts("0x");
for (i = 7; i >=0; i--)
{
if (arr[i] >= 0 && arr[i] <= 9)
putchar(arr[i] + '0');
else if(arr[i] >= 0xA && arr[i] <= 0xF)
putchar(arr[i] - 0xA + 'A');
}
}
//Print the variable with initial value 0
int g_A = 0;
int g_B;
int main(void)
{
uart0_init();
puts("nrg_A = ");
printHex(g_A);
puts("nr");
In the above code, the bss segment g_A is equal to an inexplicable value and is not equal to 0, so the bss segment needs to be cleaned up.
Modify the lds link file
SECTIONS {
.text 0 : { *(.text) }
.rodata : { *(.rodata) }
.data 0x30000000 : AT(0x700)
{
data_load_addr = LOADADDR(.data);
data_start = . ;
*(.data)
data_end = . ;
}
bss_start = .; //bss start address is the current position
.bss : { *(.bss) *(.COMMON) }
bss_end = .; //bss end address is also the current position
}
Modify start.s and clear the bss segment
/* Clear BSS segment */
ldr r1, =bss_start
ldr r2, =bss_end
move r3, #0
clean:
strb r3, [r1]
add r1, r1, #1
cmp r1, r2
bne clean
bl main
halt:
The current code global variable is 0. With just a few lines of code, you can save dozens or even thousands of global variables storage space.
Previous article:S3c2440 code relocation details 2---Introduction and simple test of link script
Next article:S3c2440 code relocation details 4 --- copy code and link script improvements
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- [TI star product limited time purchase] +CC2640R2
- What does the ratio difference in [ratio difference compensation] in the energy metering chip ATT7022 mean?
- How to choose resistors in circuit design?
- A time-delayed shutdown circuit
- Automotive 10V-80V Ultra-Wide Vin, 12V Vout Flyback Reference Design for 48V Car Battery
- TI Wireless MCU Offline Automatic Burning Instructions
- Application of Single Pair Ethernet in Building Automation
- Small and exquisite open source Python learning board Mini SAM
- TouchGFX Design" + graph waveform drawing 2
- Let you know the composition and indicators of the voltage-stabilized power supply module