Discussion:
ARM GCC: MOVT/MOVW reloacations error
Pavel Pavlov
2010-07-06 00:50:37 UTC
Permalink
I'm compiling for armv7 windows mobile (coff-pe). The problem I have is that my build of gcc tries to use MOVT/MOVW in the following case:

static void test_func(){}

void test(struct teststruct * ts)
{
ts->func = test_func;
}

The generated asm will be:
...
movw r4, #:lower16:test_func
movt r4, #:upper16:test_func

When compiling I get this error:
GNU assembler version 2.20.51 (arm-mingw32ce) using BFD version (GNU Binutils) 2.20.51.20091016
test.s: Assembler messages:
...
test.s:10: Error: cannot represent BFD_RELOC_ARM_MOVW relocation in this object file format
test.s:11: Error: cannot represent BFD_RELOC_ARM_MOVT relocation in this object file format
...


basically, it simply fails in my case because such asm cannot work on windows, and I'm not sure if such thing can work anywhere else.
Can somebody maybe recommend where I need to look for in gcc code to make gcc not generate movw/movt sequences for functions (or anything else that isn't a real constant at compile time)?


Thanks
Jie Zhang
2010-07-06 05:53:26 UTC
Permalink
Post by Pavel Pavlov
static void test_func(){}
void test(struct teststruct * ts)
{
ts->func = test_func;
}
...
movw r4, #:lower16:test_func
movt r4, #:upper16:test_func
GNU assembler version 2.20.51 (arm-mingw32ce) using BFD version (GNU Binutils) 2.20.51.20091016
...
test.s:10: Error: cannot represent BFD_RELOC_ARM_MOVW relocation in this object file format
test.s:11: Error: cannot represent BFD_RELOC_ARM_MOVT relocation in this object file format
...
basically, it simply fails in my case because such asm cannot work on windows, and I'm not sure if such thing can work anywhere else.
ARM ELF targets use movw/movt. But apparently binutils for ARM COFF
targets cannot handle such relocations. So I think it might be a good to
disable it for ARM COFF targets.
Post by Pavel Pavlov
Can somebody maybe recommend where I need to look for in gcc code to make gcc not generate movw/movt sequences for functions (or anything else that isn't a real constant at compile time)?
You could try this draft patch.


Regards,
--
Jie Zhang
CodeSourcery
Pavel Pavlov
2010-07-06 17:02:03 UTC
Permalink
-----Original Message-----
Subject: Re: ARM GCC: MOVT/MOVW reloacations error
Post by Pavel Pavlov
I'm compiling for armv7 windows mobile (coff-pe). The problem I have is that
static void test_func(){}
void test(struct teststruct * ts)
{
ts->func = test_func;
}
...
movw r4, #:lower16:test_func
movt r4, #:upper16:test_func
GNU assembler version 2.20.51 (arm-mingw32ce) using BFD version (GNU
Binutils) 2.20.51.20091016
...
test.s:10: Error: cannot represent BFD_RELOC_ARM_MOVW relocation in
this object file format
test.s:11: Error: cannot represent BFD_RELOC_ARM_MOVT relocation in
this object file format ...
basically, it simply fails in my case because such asm cannot work on windows,
and I'm not sure if such thing can work anywhere else.
ARM ELF targets use movw/movt. But apparently binutils for ARM COFF targets
cannot handle such relocations. So I think it might be a good to disable it for
ARM COFF targets.
Post by Pavel Pavlov
Can somebody maybe recommend where I need to look for in gcc code to
make gcc not generate movw/movt sequences for functions (or anything else
that isn't a real constant at compile time)?
You could try this draft patch.
[Pavel Pavlov]
Thanks I'm rebuilding now and will write back if it fixes the problem. Initially, I modified arm_rtx_costs_1 to bump up costs of movt/movw pair so that gcc prefers to use regular load instruction.
The question I have about your patch: will it have negative effect on real constants: for example, if I had something like int x = 0x12439821; and the most the best way in this case is to use movt/movw pair, will gcc try to use ldr instead or your patch affects only relocatable symbols?
Thanks
Pavel Pavlov
2010-07-12 19:25:20 UTC
Permalink
-----Original Message-----
Sent: Tuesday, July 06, 2010 01:53
To: Pavel Pavlov
Subject: Re: ARM GCC: MOVT/MOVW reloacations error
Post by Pavel Pavlov
I'm compiling for armv7 windows mobile (coff-pe). The problem I have is
static void test_func(){}
void test(struct teststruct * ts)
{
ts->func = test_func;
}
...
movw r4, #:lower16:test_func
movt r4, #:upper16:test_func
GNU assembler version 2.20.51 (arm-mingw32ce) using BFD version (GNU
Binutils) 2.20.51.20091016
...
test.s:10: Error: cannot represent BFD_RELOC_ARM_MOVW relocation in
this object file format
test.s:11: Error: cannot represent BFD_RELOC_ARM_MOVT relocation in
this object file format ...
basically, it simply fails in my case because such asm cannot work on
windows, and I'm not sure if such thing can work anywhere else.
ARM ELF targets use movw/movt. But apparently binutils for ARM COFF
targets cannot handle such relocations. So I think it might be a good to
disable it for ARM COFF targets.
Post by Pavel Pavlov
Can somebody maybe recommend where I need to look for in gcc code to
make gcc not generate movw/movt sequences for functions (or anything
else that isn't a real constant at compile time)?
You could try this draft patch.
Hi, I tried that patch and it fixes the issue. However, I have a question related to the original error.
Assembler cries than that it cannot represent that sequence in coff object file, but technically that kind of relocs are supported by windows loader:
Winnt.h contains flags for relocs and the flags for MOVW/MOVT sequence should be IMAGE_REL_BASED_HIGH and IMAGE_REL_BASED_LOW.
Probably it's more related to binutils than to gcc, hopefully somebody from binutils can comment on that.

Thanks
Jie Zhang
2010-07-13 00:36:40 UTC
Permalink
Post by Pavel Pavlov
-----Original Message-----
Sent: Tuesday, July 06, 2010 01:53
To: Pavel Pavlov
Subject: Re: ARM GCC: MOVT/MOVW reloacations error
Post by Pavel Pavlov
I'm compiling for armv7 windows mobile (coff-pe). The problem I have is
static void test_func(){}
void test(struct teststruct * ts)
{
ts->func = test_func;
}
...
movw r4, #:lower16:test_func
movt r4, #:upper16:test_func
GNU assembler version 2.20.51 (arm-mingw32ce) using BFD version (GNU
Binutils) 2.20.51.20091016
...
test.s:10: Error: cannot represent BFD_RELOC_ARM_MOVW relocation in
this object file format
test.s:11: Error: cannot represent BFD_RELOC_ARM_MOVT relocation in
this object file format ...
basically, it simply fails in my case because such asm cannot work on
windows, and I'm not sure if such thing can work anywhere else.
ARM ELF targets use movw/movt. But apparently binutils for ARM COFF
targets cannot handle such relocations. So I think it might be a good to
disable it for ARM COFF targets.
Post by Pavel Pavlov
Can somebody maybe recommend where I need to look for in gcc code to
make gcc not generate movw/movt sequences for functions (or anything
else that isn't a real constant at compile time)?
You could try this draft patch.
Hi, I tried that patch and it fixes the issue. However, I have a question related to the original error.
Winnt.h contains flags for relocs and the flags for MOVW/MOVT sequence should be IMAGE_REL_BASED_HIGH and IMAGE_REL_BASED_LOW.
Probably it's more related to binutils than to gcc, hopefully somebody from binutils can comment on that.
Yes. If you want to use these two instructions in COFF format, you have
to teach binutils to handle the relocations for them in COFF format.
--
Jie Zhang
CodeSourcery
Loading...