gcc - Invalid operands for binary AND (&) -


i have "assembly" file (containing directives)

// declare protected region somewhere within stack .equiv prot_start, $stack_top & 0xffffff00 - 0x1400 .equiv prot_end,   $stack_top & 0xffffff00 - 0x0c00 

combined linker script:

sections {    "$stack_top"   = 0x10000; } 

assembling produces output

file.s: assembler messages: file.s: error: invalid operands (*und* , *abs* sections) `&' when setting `prot_start' file.s: error: invalid operands (*und* , *abs* sections) `&' when setting `prot_end' 

how can make work?

why not possible?

you have linked gas docs, rationale inability?

answer: gas must communicate operations linker through elf object file, , things can conveyed + , - (- + negative value). fundamental limition of elf format, , not lazyness gas devs.

when gas compiles object file, link step follow, , relocation determine final value of symbol.

question: why can + conveyed, not &?

answer: because + transitive: (a + b) + c == + (b + c) + , & not "transitive together": (a & b) + c!= & (b + c).

let see how + conveyed through elf format convince ourselves & not possible.

first learn relocation if not familiar it: https://stackoverflow.com/a/30507725/895245

let's minimize example generate same error:

a: .long s b: .long s + 0x12345678 /* c: .long s & 1 */ s: 

compile , decompile:

as --32 -o main.o main.s objdump -dzr main.o 

the output contains:

00000000 <a>:    0:   08 00                   or     %al,(%eax)             0: r_386_32 .text    2:   00 00                   add    %al,(%eax)  00000004 <b>:    4:   80 56 34 12             adcb   $0x12,0x34(%esi)             4: r_386_32 .text 

ignore disassembly since not code, , @ symbols, bytes , relocations.

we have 2 r_386_32 relocations. system v abi ia-32 (which defines elf format), type of relocation calculated as:

s + 

where:

  • s: value before relocation in object file.

    value of a before relocation == 08 00 00 00 == 8 in little endian

    value of b before relocation == 80 56 34 12 == 0x12345680 in little endian

  • a: addend, field of rellocation entry, here 0 (not shown objdump), lets forget it.

when relocation happens:

  • a replaced with:

    address of text section + 8 

    there + 8 because s: 8th byte of text section, preceded 2 longs.

  • b replaced with:

     address of text section + (0x12345678 + 8)  ==  address of text section + 0x12345680 

    aha, why 0x12345680 appeared on object file!

so we've seen, possible express + on elf file adding actual offset.

but not possible express & mechanism (or other know of), because don't address of text section after relocation, can't apply & it.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -