Discussion:
Question regarding the arm gcc 5.3 to build android
yfw
2016-03-31 00:18:23 UTC
Permalink
Hi folks,
I am trying to use arm gcc 5.3 to build part of android AOSP and hit
following issue with arm gcc 5.3:

The gcc cmd line is like:
/opt/work/acadine/mem_shrink/B2G-v2.5/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-5.3-linaro/bin/arm-linux-androideabi-g++
-I external/libcxx/include -I system/core/libbacktrace -I
out/target/product/linaro_arm/obj/SHARED_LIBRARIES/libbacktrace_intermediates
-I
out/target/product/linaro_arm/gen/SHARED_LIBRARIES/libbacktrace_intermediates
-I libnativehelper/include/nativehelper -I system/core/base/include -I
external/libunwind/include -isystem system/core/include -isystem
system/media/audio/include -isystem hardware/libhardware/include
-isystem hardware/libhardware_legacy/include -isystem
hardware/ril/include -isystem libnativehelper/include -isystem
frameworks/native/include -isystem frameworks/native/opengl/include
-isystem frameworks/av/include -isystem frameworks/base/include -isystem
out/target/product/linaro_arm/obj/include -isystem
bionic/libc/arch-arm/include -isystem bionic/libc/include -isystem
bionic/libc/kernel/uapi -isystem bionic/libc/kernel/uapi/asm-arm
-isystem bionic/libm/include -isystem bionic/libm/include/arm -c
-fno-exceptions -Wno-multichar -msoft-float -ffunction-sections
-fdata-sections -funwind-tables -fstack-protector -Wa,--noexecstack
-Werror=format-security -D_FORTIFY_SOURCE=2 -fno-short-enums
-no-canonical-prefixes -fno-canonical-system-headers -march=armv7-a
-mfloat-abi=softfp -mfpu=vfpv3-d16 -include
build/core/combo/include/arch/linux-arm/AndroidConfig.h -I
build/core/combo/include/arch/linux-arm/ -Wno-psabi -mthumb-interwork
-DANDROID -fmessage-length=0 -W -Wall -Wno-unused -Winit-self
-Wpointer-arith -Werror=return-type -Werror=non-virtual-dtor
-Werror=address -Werror=sequence-point -DNDEBUG -g -Wstrict-aliasing=2
-fgcse-after-reload -frerun-cse-after-loop -frename-registers -DNDEBUG
-UDEBUG -fvisibility-inlines-hidden -DANDROID -fmessage-length=0 -W
-Wall -Wno-unused -Winit-self -Wpointer-arith -Wsign-promo -std=gnu++11
-Werror=return-type -Werror=non-virtual-dtor -Werror=address
-Werror=sequence-point -DNDEBUG -UDEBUG -mthumb -Os -fomit-frame-pointer
-fno-strict-aliasing -fno-rtti -Wall -Werror -fPIC -D_USING_LIBCXX
-std=gnu++11 -Werror=int-to-pointer-cast
-Werror=pointer-to-int-cast -MD -MF
out/target/product/linaro_arm/obj/SHARED_LIBRARIES/libbacktrace_intermediates/UnwindCurrent.d
-o
out/target/product/linaro_arm/obj/SHARED_LIBRARIES/libbacktrace_intermediates/UnwindCurrent.o
system/core/libbacktrace/UnwindCurrent.cpp

And I got error:
/tmp/ccZ40ViQ.s: Assembler messages:
/tmp/ccZ40ViQ.s:1752: Error: selected processor does not support ARM
mode `cbnz r6,.L91'
/tmp/ccZ40ViQ.s:1758: Error: selected processor does not support ARM
mode `cbnz r0,.L92'
/tmp/ccZ40ViQ.s:1763: Error: selected processor does not support ARM
mode `cbz r1,.L107'
/tmp/ccZ40ViQ.s:1941: Error: selected processor does not support ARM
mode `cbz r6,.L100'

But if I use the arm gcc 4.9, there is no any build issue.

the "-dumpspecs" output of gcc 5.3 was attached. Thanks.


Regards
Yin, Fengwei
Jim Wilson
2016-03-31 01:06:13 UTC
Permalink
/tmp/ccZ40ViQ.s:1752: Error: selected processor does not support ARM mode
`cbnz r6,.L91'
Looking at gcc, I see that in thumb2 mode, for a conditional branch,
it will emit cbnz if the target is in range and it is using a thumb2
low register, otherwise it emits cmp/bne. So this perhaps could be a
bug with the compiler calculating instruction sizes wrong, and hence
getting the range calculation from the branch to the target label
wrong. We would need a reproducible testcase to investigate. The
easiest way to do this if to add --save-temps to the g++ command, and
then send us the UnwindCurrent.ii file. We also need the g++ command
line, but you already gave us that. Otherwise, we have to figure out
how to build AOSP with gcc-5.3. I'm not sure if anyone on the
toolchain team is doing that regularly.

There could also be something else going wrong here, e.g. the code
could have extended asms using cbnz which aren't valid in thumb2 mode,
the assembler could be somehow in thumb1 mode, etc, but these seem
less likely in this case.

Jim
Jim Wilson
2016-03-31 04:47:30 UTC
Permalink
Thanks a lot for your quick response. The .ii file was attached.
In UnwindFromContext, there is an asm that forces the assembler into ARM mode.

if (ucontext == nullptr) {
int ret = (({ unw_tdep_context_t *unw_ctx = (&context_); register unsigned \
long *unw_base asm ("r0") = unw_ctx->regs; __asm__ __volatile__ ( ".align 2\nbx\
pc\nnop\n.code 32\n" "stmia %[base], {r0-r15}\n" "orr %[base], pc, #1\nbx %[ba\
se]" : [base] "+r" (unw_base) : : "memory", "cc"); }), 0);

The ".code 32" puts us in ARM mode.

GCC still thinks that we are in thumb mode though, and continues to
emit thumb instructions, some of which have no arm mode equivalent,
e.g. cbnz and cbz.

I don't see any convenient push/pop for thumb/arm mode. This is
probably a macro expanded into the asm. You could have two versions
of the asm, one that gets used when __thumb__ is defined and one that
gets used when __thumb__ is not defined. The __thumb__ version would
switch back into thumb mode at the end with a ".thumb" pseudo-op.

Or alternatively, don't build with -mthumb.

Jim
fengwei.yin
2016-03-31 06:07:46 UTC
Permalink
Hi Jim,
Post by Jim Wilson
Thanks a lot for your quick response. The .ii file was attached.
In UnwindFromContext, there is an asm that forces the assembler into ARM mode.
if (ucontext == nullptr) {
int ret = (({ unw_tdep_context_t *unw_ctx = (&context_); register unsigned \
long *unw_base asm ("r0") = unw_ctx->regs; __asm__ __volatile__ ( ".align 2\nbx\
pc\nnop\n.code 32\n" "stmia %[base], {r0-r15}\n" "orr %[base], pc, #1\nbx %[ba\
se]" : [base] "+r" (unw_base) : : "memory", "cc"); }), 0);
The ".code 32" puts us in ARM mode.
GCC still thinks that we are in thumb mode though, and continues to
emit thumb instructions, some of which have no arm mode equivalent,
e.g. cbnz and cbz.
I don't see any convenient push/pop for thumb/arm mode. This is
probably a macro expanded into the asm. You could have two versions
of the asm, one that gets used when __thumb__ is defined and one that
gets used when __thumb__ is not defined. The __thumb__ version would
switch back into thumb mode at the end with a ".thumb" pseudo-op.
Or alternatively, don't build with -mthumb.
The thing is gcc 4.9 has no such problem. And I don't think it's possible to
disable thumb because it's a global flag for AOSP build.

I'd like to understand why Bero has no such issue in his side.

Regards
Yin, Fengwei
Post by Jim Wilson
Jim
Jim Wilson
2016-03-31 17:26:42 UTC
Permalink
Because gcc 4.9 could build this file without any issue, I apply
--save-temps
with gcc 4.9. The ii file is attached. Can't see significant differences.
There is a patch in gcc-5 to make unified assembler syntax the
default. Unfortunately, it changes how extended asms work, which is
perhaps a bug. The message claims it doesn't affect extended asms,
but it does.
https://gcc.gnu.org/ml/gcc-patches/2015-11/msg01196.html
The interesting bit is the change to ASM_APP_OFF.

gcc-4.9 emits a .thumb after the extended asm to switch back into
thumb mode just in case. gcc-5.3 instead emits .syntax unified, which
doesn't change the arm/thumb mode, just the syntax supported. This is
arguably a bug, but this doesn't immediately help you. It could take
a little time to get gcc-5.x source fixed, and then the compiler
binary releases. Or alternatively we could fix the asm to work with
gcc 5.

Jim
fengwei.yin
2016-04-01 00:04:34 UTC
Permalink
Hi Jim,
Post by Jim Wilson
Because gcc 4.9 could build this file without any issue, I apply
--save-temps
with gcc 4.9. The ii file is attached. Can't see significant differences.
There is a patch in gcc-5 to make unified assembler syntax the
default. Unfortunately, it changes how extended asms work, which is
perhaps a bug. The message claims it doesn't affect extended asms,
but it does.
https://gcc.gnu.org/ml/gcc-patches/2015-11/msg01196.html
The interesting bit is the change to ASM_APP_OFF.
gcc-4.9 emits a .thumb after the extended asm to switch back into
thumb mode just in case. gcc-5.3 instead emits .syntax unified, which
doesn't change the arm/thumb mode, just the syntax supported. This is
arguably a bug, but this doesn't immediately help you. It could take
a little time to get gcc-5.x source fixed, and then the compiler
binary releases. Or alternatively we could fix the asm to work with
gcc 5.
Thanks a lot for looking at this.

I think fixing asm is the thing we should try here. Removing thumb is not
acceptable because we use gcc5.3 for AOSP for memory reduction.

This part of code was from libunwind actually. And it's defined like:

/* There is no getcontext() on ARM. Use a stub version which only saves GP
registers. FIXME: Not ideal, may not be sufficient for all libunwind
use cases. Stores pc+8, which is only approximately correct, really. */
#ifndef __thumb__
#define unw_tdep_getcontext(uc) (({ \
unw_tdep_context_t *unw_ctx = (uc); \
register unsigned long *unw_base asm ("r0") = unw_ctx->regs; \
__asm__ __volatile__ ( \
"stmia %[base], {r0-r15}" \
: : [base] "r" (unw_base) : "memory"); \
}), 0)
#else /* __thumb__ */
#define unw_tdep_getcontext(uc) (({ \
unw_tdep_context_t *unw_ctx = (uc); \
register unsigned long *unw_base asm ("r0") = unw_ctx->regs; \
__asm__ __volatile__ ( \
".align 2\nbx pc\nnop\n.code 32\n" \
"stmia %[base], {r0-r15}\n" \
"orr %[base], pc, #1\nbx %[base]" \
: [base] "+r" (unw_base) : : "memory", "cc"); \
}), 0)
#endif

Remove the __thumb__ part?


Regards
Yin, Fengwei
Post by Jim Wilson
Jim
Jim Wilson
2016-04-01 01:30:34 UTC
Permalink
Post by fengwei.yin
Remove the __thumb__ part?
If you remove the __thumb__ part, then you will get an assembler error.

palantir:2025$ arm-linux-gnueabi-as UnwindCurrent.s
UnwindCurrent.s: Assembler messages:
UnwindCurrent.s:1504: Error: PC not allowed in register list -- `stmia
r0,{r0-r15}'
palantir:2026$

This instruction is not a valid thumb instruction. It is a valid arm
instruction, but deprecated. The assembler gives an error because you
are in thumb mode. Since you already have a __thumb__ version of the
macro, you can put a ".thumb" directive at the end of the asm, after
the orr instruction, to manually switch back into thumb mode.

Jim
fengwei.yin
2016-04-01 01:32:32 UTC
Permalink
Post by Jim Wilson
Post by fengwei.yin
Remove the __thumb__ part?
If you remove the __thumb__ part, then you will get an assembler error.
palantir:2025$ arm-linux-gnueabi-as UnwindCurrent.s
UnwindCurrent.s:1504: Error: PC not allowed in register list -- `stmia
r0,{r0-r15}'
palantir:2026$
This instruction is not a valid thumb instruction. It is a valid arm
instruction, but deprecated. The assembler gives an error because you
are in thumb mode. Since you already have a __thumb__ version of the
macro, you can put a ".thumb" directive at the end of the asm, after
the orr instruction, to manually switch back into thumb mode.
Cool. Thanks a lot. I will try it.
Post by Jim Wilson
Jim
Ramana Radhakrishnan
2016-04-01 09:52:36 UTC
Permalink
Post by Jim Wilson
Because gcc 4.9 could build this file without any issue, I apply
--save-temps
with gcc 4.9. The ii file is attached. Can't see significant differences.
There is a patch in gcc-5 to make unified assembler syntax the
default. Unfortunately, it changes how extended asms work, which is
perhaps a bug. The message claims it doesn't affect extended asms,
but it does.
https://gcc.gnu.org/ml/gcc-patches/2015-11/msg01196.html
The interesting bit is the change to ASM_APP_OFF.
The patch was intended to make unified asm as default for ARM state without
having any impact with respect to unified / divided syntax for inline assembler.

The change to remove .arm and .thumb is a thinko and clearly a bug : I'll fix it shortly upstream.

regards
Ramana
Post by Jim Wilson
gcc-4.9 emits a .thumb after the extended asm to switch back into
thumb mode just in case. gcc-5.3 instead emits .syntax unified, which
doesn't change the arm/thumb mode, just the syntax supported. This is
arguably a bug, but this doesn't immediately help you. It could take
a little time to get gcc-5.x source fixed, and then the compiler
binary releases. Or alternatively we could fix the asm to work with
gcc 5.
Jim
_______________________________________________
linaro-toolchain mailing list
https://lists.linaro.org/mailman/listinfo/linaro-toolchain
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Ramana Radhakrishnan
2016-04-01 10:04:01 UTC
Permalink
Post by Jim Wilson
Because gcc 4.9 could build this file without any issue, I apply
--save-temps
with gcc 4.9. The ii file is attached. Can't see significant differences.
There is a patch in gcc-5 to make unified assembler syntax the
default. Unfortunately, it changes how extended asms work, which is
perhaps a bug. The message claims it doesn't affect extended asms,
but it does.
https://gcc.gnu.org/ml/gcc-patches/2015-11/msg01196.html
The interesting bit is the change to ASM_APP_OFF.
This is now https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70496 for FSF trunk.

Sorry about the breakage.

Ramana
Post by Jim Wilson
gcc-4.9 emits a .thumb after the extended asm to switch back into
thumb mode just in case. gcc-5.3 instead emits .syntax unified, which
doesn't change the arm/thumb mode, just the syntax supported. This is
arguably a bug, but this doesn't immediately help you. It could take
a little time to get gcc-5.x source fixed, and then the compiler
binary releases. Or alternatively we could fix the asm to work with
gcc 5.
Jim
_______________________________________________
linaro-toolchain mailing list
https://lists.linaro.org/mailman/listinfo/linaro-toolchain
Christophe Lyon
2016-04-03 19:58:18 UTC
Permalink
On 1 April 2016 at 12:04, Ramana Radhakrishnan
Post by Ramana Radhakrishnan
Post by Jim Wilson
Because gcc 4.9 could build this file without any issue, I apply
--save-temps
with gcc 4.9. The ii file is attached. Can't see significant differences.
There is a patch in gcc-5 to make unified assembler syntax the
default. Unfortunately, it changes how extended asms work, which is
perhaps a bug. The message claims it doesn't affect extended asms,
but it does.
https://gcc.gnu.org/ml/gcc-patches/2015-11/msg01196.html
The interesting bit is the change to ASM_APP_OFF.
This is now https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70496 for FSF trunk.
Sorry about the breakage.
Ramana
As Ramana fixed it promptly on trunk, we'll backport it and it will
be available in our next linaro-gcc-5.x snapshot.

Thanks,

Christophe.
Post by Ramana Radhakrishnan
Post by Jim Wilson
gcc-4.9 emits a .thumb after the extended asm to switch back into
thumb mode just in case. gcc-5.3 instead emits .syntax unified, which
doesn't change the arm/thumb mode, just the syntax supported. This is
arguably a bug, but this doesn't immediately help you. It could take
a little time to get gcc-5.x source fixed, and then the compiler
binary releases. Or alternatively we could fix the asm to work with
gcc 5.
Jim
_______________________________________________
linaro-toolchain mailing list
https://lists.linaro.org/mailman/listinfo/linaro-toolchain
_______________________________________________
linaro-toolchain mailing list
https://lists.linaro.org/mailman/listinfo/linaro-toolchain
fengwei.yin
2016-04-04 13:11:33 UTC
Permalink
Hi Christophe,
Post by Christophe Lyon
On 1 April 2016 at 12:04, Ramana Radhakrishnan
Post by Ramana Radhakrishnan
Post by Jim Wilson
Because gcc 4.9 could build this file without any issue, I apply
--save-temps
with gcc 4.9. The ii file is attached. Can't see significant differences.
There is a patch in gcc-5 to make unified assembler syntax the
default. Unfortunately, it changes how extended asms work, which is
perhaps a bug. The message claims it doesn't affect extended asms,
but it does.
https://gcc.gnu.org/ml/gcc-patches/2015-11/msg01196.html
The interesting bit is the change to ASM_APP_OFF.
This is now https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70496 for FSF trunk.
Sorry about the breakage.
Ramana
As Ramana fixed it promptly on trunk, we'll backport it and it will
be available in our next linaro-gcc-5.x snapshot.
Thanks a lot. I will try once the next snapshot is ready.

Regards
Yin, Fengwei
Post by Christophe Lyon
Thanks,
Christophe.
Post by Ramana Radhakrishnan
Post by Jim Wilson
gcc-4.9 emits a .thumb after the extended asm to switch back into
thumb mode just in case. gcc-5.3 instead emits .syntax unified, which
doesn't change the arm/thumb mode, just the syntax supported. This is
arguably a bug, but this doesn't immediately help you. It could take
a little time to get gcc-5.x source fixed, and then the compiler
binary releases. Or alternatively we could fix the asm to work with
gcc 5.
Jim
_______________________________________________
linaro-toolchain mailing list
https://lists.linaro.org/mailman/listinfo/linaro-toolchain
_______________________________________________
linaro-toolchain mailing list
https://lists.linaro.org/mailman/listinfo/linaro-toolchain
Loading...