Meaning of ELF64_R_SYM(rela->r_info)

Nick Clifton nickc@redhat.com
Thu Apr 22 14:02:00 GMT 2021


Hi Peng,

> Why "call" is used here? Isn't it better to use "call" in both the
> assembly code and the objdump output to make the result consistent?

The compiler has generated a "call" instruction, but the assembler has 
chosen to replace it with "callq", resulting in smaller/faster code.

When objdump disassembles the binary file it knows nothing of the 
original compiler output, and instead just displays the instruction that 
is there.

This kind of discrepancy between compiler output and actual generated 
machine instructions is quite common, and happens for many 
architectures, not just the x86.


> Also, this assembly code is not very human writable. For example, "s"
> definition is split into 5 lines. I am more familiar with nasm syntax,
> in which, the code can be written much short. Is the as syntax this
> verbose? Or it is because it is machine generated assembly code, it is
> OK to be verbose? What the equivalent more writable code looks like?

The choice of how to lay out the assembler is up to the compiler.  It 
could choose to put multiple instructions on one line, but historically 
compilers always choose to be verbose, and only have one instruction per 
line.

A more compact version of the definition of s might look like this:

   s:
    .globl s ; .type s, @object ; .size s, 14 ; .string "Hello World2!"

But really, are 5 lines harder to read than 1 ?


> "leaq" becomes "lea" in the objdump output which is exactly the
> opposite of the "call" case (as "q" is added by objdump disassembly).
> This is again confusing. Why is so?

This is presumably a case where the assembler decides that it is not 
safe to use the LEAQ instruction, and so it replaces it with LEA.  (I am 
not an x86 assembler expert, so this is guesswork on my part).

> How to know when the -q version
> should be used when the non-q version should be used? Isn't it better
> to make them consistent throughout?

Trust the assembler.  It knows that it is doing.  If it makes a change 
to the code, there will be a good reason for it.


Cheers
   Nick



More information about the Binutils mailing list