Character table and move table in object file

From what I understand, the instructions and data in the object file have all the addresses. The first data item starts at address 0, and the first instruction also starts at address 0.

The movement table contains information about the instructions that need to be updated if the changes in the file change, for example, if the file is associated with another. Line A in the example below will be in the movement table. I do not think that B will be in the displacement table, since the address of the label "equal" refers to B. Are these the correct assumptions?

I know that the symbol table shows labels that are in the file, as well as labels that were not allowed. But what other information does the character table contain?

In addition, when the assembler translates the instructions into binary, what is placed in those instructions that have unresolved references ?. B in this example.

.data TEXT: .asciiz "Foo" .text .global main main: li t0, 1 beq t0, 1, equal #B equal: la a0, TEXT jal printf #A 
+7
source share
1 answer

Yes, your assumptions are correct. There are various types of movements that the assembler throws into the instruction, depending on the type. This is usually the offset to be added. You can use objdump -dr to view movements. For a better illustration, I changed the code a bit:

 .data .int 0 TEXT: .asciiz "Foo" .text .global main main: li $t0, 1 beq $t0, 1, equal #B bne $t0, 42, foo #C equal: la $a0, TEXT jal printf #A 

Objdump output:

 00000000 <main>: 0: 24080001 li t0,1 4: 24010001 li at,1 8: 11010004 beq t0,at,1c <equal> c: 00000000 nop 10: 2401002a li at,42 14: 1501ffff bne t0,at,14 <main+0x14> 14: R_MIPS_PC16 foo 18: 00000000 nop 0000001c <equal>: 1c: 3c040000 lui a0,0x0 1c: R_MIPS_HI16 .data 20: 0c000000 jal 0 <main> 20: R_MIPS_26 printf 24: 24840004 addiu a0,a0,4 24: R_MIPS_LO16 .data 

As you said, there is no move for beq , since this is the relative address in this object file.

The added bne (line labeled C ) refers to an external character, so although the address is relative, a move record is required. It will be of type R_MIPS_PC16 to create a 16-bit dictionary offset of the word with the symbol foo . Since the encoding of the command requires an offset from the next word, and not the current PC that uses redistribution, 1 should be subtracted and encoded as 2 ffff additions in the instruction itself.

The pseudo-instruction la was translated by the assembler into the lui / addiu (the latter in the jal delay slot). For lui a R_MIPS_HI16 movement is created in the .data section, which fills the upper 16 bits. Since the TEXT character is at address 4 in the .data section, the upper 16 bits of the offset are 0 . This means that the instruction contains an offset of 0 . Similarly, for the lower 16 bits, except there, the instruction contains an offset of 4 .

Finally, jal printf uses another kind of move, which is for the coding required by the instruction. The offset is zero, because the transition is made directly to the specified character. Note that objdump tries to be useful by decrypting this, but it does not handle the move, so the <main> output is, of course, pointless.

+7
source

All Articles