[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] "error: invalid displacement" i386 1f 'L..1' does not

From: Michael Matz
Subject: Re: [Tinycc-devel] "error: invalid displacement" i386 1f 'L..1' does not get resolved
Date: Wed, 20 Apr 2022 17:04:45 +0200 (CEST)
User-agent: Alpine 2.21 (LSU 202 2017-01-01)


On Sun, 17 Apr 2022, Volodymyr Boyko wrote:

I'm trying to assemble the following snippet of code:

.global sigsetjmp
.global __sigsetjmp
.type sigsetjmp,@function
.type __sigsetjmp,@function
        mov 8(%esp),%ecx
        jecxz 1f

        mov 4(%esp),%eax
        popl 24(%eax)
        mov %ebx,28+8(%eax)
        mov %eax,%ebx

.hidden ___setjmp
        call ___setjmp

        pushl 24(%ebx)
        mov %ebx,4(%esp)
        mov %eax,8(%esp)
        mov 28+8(%ebx),%ebx

.hidden __sigsetjmp_tail
        jmp __sigsetjmp_tail

1:      jmp ___setjmp
but getting this error:
src/signal/i386/sigsetjmp.s:8: error: invalid displacement
After renaming/moving the label around I assume the issue is that local
labels cannot be forward;1b and my_label moved to the top do work fine.

Yeah, it's related to that, but specific to the 'jexcz' opcode: the special thing about it is that it only comes in an 8-bit displacement form _and_ doesn't have an inverse form. TCC, being single-pass, has to assume that forward labels could be anywhere, and hence potentially need a 32bit form (no matter that _in this case_ it would turn out to not be necessary), so jumps are rewritten into their disp32 forms for such labels. For jecxz that can't be done. And as the inverse form doesn't exist we can't even work around this by emitting something like a hypothetical:

  jecxnz +5   ; doesn't exist!
  jmp 1f

The GNU assembler uses multiple passes to figure out that the displacement in the testcase turns out to fit into a disp8 field and hence all is well. Add a couple more opcodes between the jecxz and the 1: label to make the distance larger than 128 and see it erroring out as well.

Supporting this requires some surgery (e.g. to support the _PC8 relocation and emitting them for this case only), so is of low priority.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]