https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89502

            Bug ID: 89502
           Summary: Error: can't encode segment `%fs' with 32-bit address
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hjl.tools at gmail dot com
  Target Milestone: ---
            Target: x32

[hjl@gnu-cfl-1 xx]$ cat x.i
typedef unsigned int uint32_t;
struct ctx
{
  uint32_t A;
};

void *
buffer_copy (const struct ctx *ctx, void *resbuf)
{
  uint32_t buffer[4];
  buffer[0] = (ctx->A);
  __builtin_memcpy (resbuf, buffer, sizeof (buffer));
  return resbuf;
}
[hjl@gnu-cfl-1 xx]$ make x.o
/export/build/gnu/tools-build/gcc-mmx-debug/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/tools-build/gcc-mmx-debug/build-x86_64-linux/gcc/
-fstack-protector-strong -O1 -frename-registers -mx32  -S x.i
/export/build/gnu/tools-build/gcc-mmx-debug/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/tools-build/gcc-mmx-debug/build-x86_64-linux/gcc/
-fstack-protector-strong -O1 -frename-registers -mx32  -c -o x.o x.s
x.s: Assembler messages:
x.s:11: Error: can't encode segment `%fs' with 32-bit address
x.s:18: Error: can't encode segment `%fs' with 32-bit address
make: *** [Makefile:21: x.o] Error 1
[hjl@gnu-cfl-1 xx]$ 

The problem is

        movl    %fs:(%edx), %ecx

In x32, we can't have 0x67 prefix (from %edx) with segment override
since final address will be

segment base + zero-extended (base + index * scale + disp)

Since assembler

https://sourceware.org/bugzilla/show_bug.cgi?id=24263

doesn't know %edx is always positive, it issues an error.

Reply via email to