Bug 1106014 - cross-arm-none-gcc8-8.1.1+r262873-1.3.x86_64 -mcpu=cortex-m0plus emits incorrect arch
cross-arm-none-gcc8-8.1.1+r262873-1.3.x86_64 -mcpu=cortex-m0plus emits incorr...
Status: RESOLVED FIXED
Classification: openSUSE
Product: openSUSE Tumbleweed
Classification: openSUSE
Component: Development
Current
All All
: P5 - None : Normal (vote)
: ---
Assigned To: Richard Biener
E-mail List
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2018-08-27 05:02 UTC by William Brown
Modified: 2021-07-09 19:26 UTC (History)
4 users (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description William Brown 2018-08-27 05:02:45 UTC
Hi,

The cross-arm-none-gcc8 package in OpenSUSE may have an incorrect definition for -mcpu=cortex-m0plus. 

On Fedora27 compiling the code found in the tomu-sample repo causes the ELF to have the following details:

No version information found in this file. 
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "Cortex-M0+"
  Tag_CPU_arch: v6S-M
  Tag_CPU_arch_profile: Microcontroller
  Tag_THUMB_ISA_use: Thumb-1
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: small
  Tag_ABI_optimization_goals: Aggressive Size

Please note the Tap_CPU_arch.

On OpenSUSE the following is shown:

No version information found in this file. 
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "ARM v6K"
  Tag_CPU_arch: v6K
  Tag_CPU_arch_profile: Microcontroller
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-1
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: small
  Tag_ABI_optimization_goals: Aggressive Size

This causes the development board to fail to initialise as it is the wrong CPU arch. There are other platforms (arch linux, macOSX) where they correctly emit armv6s-m for -mcpu=cortex-m0plus.

Version of affected packages:

cross-arm-binutils-2.31-1.1.x86_64
cross-arm-none-newlib-devel-3.0.0-2.5.x86_64
cross-arm-none-gcc8-8.1.1+r262873-1.3.x86_64

Reproduction:

https://github.com/im-tomu/tomu-samples

Follow the readme, or:

git submodule init
git submodule update

make -C libopencm3
make -C usb_simple

readelf -A usb_simple/usb_simple.elf
Comment 1 Richard Biener 2018-08-27 07:59:41 UTC
Andreas added this variant.
Comment 2 Andreas Färber 2018-08-30 20:33:03 UTC
Beyond the different tool output, is there any actual problem?

https://build.opensuse.org/package/view_file/devel:gcc/gcc8/gcc.spec.in?expand=1
does not override any defaults for "%{TARGET_ARCH}" == "arm-none".

The bigger potential limitation will be in newlib:

%if "%{cross_arch}" == "arm-none"
	--with-multilib-list=armv6-m,armv7-m,armv7e-m,cortex-m7,armv7-r \
%endif

https://build.opensuse.org/package/view_file/devel:gcc/newlib/newlib.spec.in?expand=1

I also note that your openSUSE output shows Tag_ARM_ISA_use, so might this be some ARM vs. THUMB mode issue? You could try adding -mthumb or so to your CFLAGS.
Comment 3 William Brown 2018-08-31 22:47:50 UTC
Hi there,

-mthumb is part of the CFLAGS in both cases. I did ensure to check this. This issue only affects SUSE, with gcc on fedora and arch I wasn't able to see the issue. Even tweaking to ensure it's -march was v6s-m, I was unable to create a working binary. This is why I suspected a suse specific issue in the gcc toolchain related to the use of the mcpu flag's as provided.
Comment 4 Matthew Trescott 2020-10-14 08:12:33 UTC
I would guess this is an ARM vs Thumb issue too---in my case integer division was implemented in traditional ARM instructions in the copy of libgcc that is currently shipped with cross-arm-none-gcc, which caused errors when I ran it on my Cortex-M4 micro.

You can compile GCC to include the full set of libgcc binaries for different combinations of hard-float, soft-float, armv7, armv8, etc. I haven't tested this yet but I believe it should work (it's roughly the same settings as those used by Debian and the compiled binaries from ARM):

osc co openSUSE:Factory/cross-arm-none-gcc10

Edit gcc.spec.in and add

%if "%{TARGET_ARCH}" == "arm-none"
	--enable-multilib \
	--disable-decimal-float \
	--disable-libffi \
	--disable-libgomp \
	--disable-libmudflap \
	--disable-libquadmath \
	--disable-libssp \
	--disable-libstdcxx-pch \
	--disable-shared \
	--disable-threads \
	--disable-tls \
	--with-multilib-list=rmprofile \
	--without-headers \
%endif

around line 1303, then run

sh pre_checkin.sh 10
osc build --local-package

It took over half an hour to compile for me, but in the end the packages will be there in /var/tmp/build-root/openSUSE_Factory/home/abuild/rpmbuild/RPMS/x86_64. And the packages have the full set of libgcc binaries in /usr/lib64/gcc/arm-none-eabi/10/thumb.

Andreas, after I make sure this works I'd be happy to open a submitrequest on OBS. I'm just not sure whether this is quite the correct approach or not. (For example, should I enable "aprofile" in addition to "rmprofile" as described at https://gcc.gnu.org/install/configure.html ?)
Comment 5 Matthew Trescott 2020-10-14 08:13:25 UTC
For reference, here is an explanation of the problem that led me to this solution: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60464
Comment 6 Matthew Trescott 2020-10-23 06:21:30 UTC
There is a little more work required than I realized; newlib also needs to be rebuilt. This requires applying the same steps outlined above to the cross-arm-none-eabi-gcc10-bootstrap package, building it, then using that package to build cross-arm-none-newlib-devel. (I put the gcc bootstrap packages in my Documents folder and used osc build --local-package --prefer-pkgs=~/Documents). This is required because newlib calls

arm-none-eabi-gcc --print-multi-lib

during the configure stage to determine the which multilib architectures to build. If the bootstrap GCC wasn't compiled with all the multilibs, newlib won't have them enabled either.

With GCC 10 at least this requires updating the package from newlib 2.1.0 to 2.3.0; otherwise it'll attempt to compile this assembly file as Thumb and fail: https://sourceware.org/git/?p=newlib-cygwin.git;a=commit;h=cc430406ac09d99570b5218668f2bb00371ae983

I am now able to run ChibiOS on my Cortex-M4 board without any problems, including calling functions using newlib's memcpy(). Should I open the necessary submitrequests on OBS?
Comment 7 Richard Biener 2020-10-26 07:21:54 UTC
(In reply to Matthew Trescott from comment #6)
> There is a little more work required than I realized; newlib also needs to
> be rebuilt. This requires applying the same steps outlined above to the
> cross-arm-none-eabi-gcc10-bootstrap package, building it, then using that
> package to build cross-arm-none-newlib-devel. (I put the gcc bootstrap
> packages in my Documents folder and used osc build --local-package
> --prefer-pkgs=~/Documents). This is required because newlib calls
> 
> arm-none-eabi-gcc --print-multi-lib
> 
> during the configure stage to determine the which multilib architectures to
> build. If the bootstrap GCC wasn't compiled with all the multilibs, newlib
> won't have them enabled either.
> 
> With GCC 10 at least this requires updating the package from newlib 2.1.0 to
> 2.3.0; otherwise it'll attempt to compile this assembly file as Thumb and
> fail:
> https://sourceware.org/git/?p=newlib-cygwin.git;a=commit;
> h=cc430406ac09d99570b5218668f2bb00371ae983
> 
> I am now able to run ChibiOS on my Cortex-M4 board without any problems,
> including calling functions using newlib's memcpy(). Should I open the
> necessary submitrequests on OBS?

Yes please - if you can manage to keep them to small isolated changes that
will ease review/acceptance.
Comment 8 Matthew Trescott 2020-10-27 19:04:01 UTC
The changes are submitted as https://build.opensuse.org/request/show/844447 and https://build.opensuse.org/request/show/844448
Comment 9 OBSbugzilla Bot 2020-10-28 15:00:07 UTC
This is an autogenerated message for OBS integration:
This bug (1106014) was mentioned in
https://build.opensuse.org/request/show/844614 Factory / gcc10
Comment 10 Richard Biener 2020-12-07 09:43:27 UTC
Should be fixed in GCC10+ then.
Comment 11 Matthew Trescott 2020-12-07 12:15:20 UTC
Unfortunately the newlib changes have not been rolled out to Tumbleweed yet: https://build.opensuse.org/request/show/844506

And Newlib has not been rebuilt in Tumbleweed with all the multilibs. I don't think it should be marked as resolved yet.
Comment 12 Richard Biener 2020-12-07 12:58:44 UTC
(In reply to Matthew Trescott from comment #11)
> Unfortunately the newlib changes have not been rolled out to Tumbleweed yet:
> https://build.opensuse.org/request/show/844506
> 
> And Newlib has not been rebuilt in Tumbleweed with all the multilibs. I
> don't think it should be marked as resolved yet.

Ah, I missed that.  Accepted and forwarded a fix.
Comment 13 OBSbugzilla Bot 2020-12-07 13:30:06 UTC
This is an autogenerated message for OBS integration:
This bug (1106014) was mentioned in
https://build.opensuse.org/request/show/853584 Factory / newlib
Comment 15 Swamp Workflow Management 2021-05-28 13:16:34 UTC
SUSE-RU-2021:1796-1: An update that has 7 recommended fixes can now be installed.

Category: recommended (moderate)
Bug References: 1029961,1106014,1178577,1178624,1178675,1182016,1185337
CVE References: 
JIRA References: 
Sources used:
SUSE OpenStack Cloud Crowbar 9 (src):    gcc10-10.3.0+git1587-1.6.2
SUSE OpenStack Cloud Crowbar 8 (src):    gcc10-10.3.0+git1587-1.6.2
SUSE OpenStack Cloud 9 (src):    gcc10-10.3.0+git1587-1.6.2
SUSE OpenStack Cloud 8 (src):    gcc10-10.3.0+git1587-1.6.2
SUSE Linux Enterprise Server for SAP 12-SP4 (src):    gcc10-10.3.0+git1587-1.6.2
SUSE Linux Enterprise Server for SAP 12-SP3 (src):    gcc10-10.3.0+git1587-1.6.2
SUSE Linux Enterprise Server 12-SP5 (src):    gcc10-10.3.0+git1587-1.6.2
SUSE Linux Enterprise Server 12-SP4-LTSS (src):    gcc10-10.3.0+git1587-1.6.2
SUSE Linux Enterprise Server 12-SP3-LTSS (src):    gcc10-10.3.0+git1587-1.6.2
SUSE Linux Enterprise Server 12-SP3-BCL (src):    gcc10-10.3.0+git1587-1.6.2
SUSE Linux Enterprise Server 12-SP2-BCL (src):    gcc10-10.3.0+git1587-1.6.2
SUSE Linux Enterprise Module for Toolchain 12 (src):    cross-nvptx-gcc10-10.3.0+git1587-1.6.1, gcc10-10.3.0+git1587-1.6.2
HPE Helion Openstack 8 (src):    gcc10-10.3.0+git1587-1.6.2

NOTE: This line indicates an update has been released for the listed product(s). At times this might be only a partial fix. If you have questions please reach out to maintenance coordination.
Comment 16 Swamp Workflow Management 2021-06-04 13:18:27 UTC
SUSE-RU-2021:1861-1: An update that has 6 recommended fixes can now be installed.

Category: recommended (moderate)
Bug References: 1029961,1106014,1178577,1178624,1178675,1182016
CVE References: 
JIRA References: 
Sources used:
SUSE MicroOS 5.0 (src):    gcc10-10.3.0+git1587-1.6.4
SUSE Manager Server 4.0 (src):    cross-nvptx-gcc10-10.3.0+git1587-1.6.3, gcc10-10.3.0+git1587-1.6.4
SUSE Manager Retail Branch Server 4.0 (src):    cross-nvptx-gcc10-10.3.0+git1587-1.6.3, gcc10-10.3.0+git1587-1.6.4
SUSE Manager Proxy 4.0 (src):    cross-nvptx-gcc10-10.3.0+git1587-1.6.3, gcc10-10.3.0+git1587-1.6.4
SUSE Linux Enterprise Server for SAP 15-SP1 (src):    cross-nvptx-gcc10-10.3.0+git1587-1.6.3, gcc10-10.3.0+git1587-1.6.4
SUSE Linux Enterprise Server for SAP 15 (src):    cross-nvptx-gcc10-10.3.0+git1587-1.6.3, gcc10-10.3.0+git1587-1.6.4
SUSE Linux Enterprise Server 15-SP1-LTSS (src):    cross-nvptx-gcc10-10.3.0+git1587-1.6.3, gcc10-10.3.0+git1587-1.6.4
SUSE Linux Enterprise Server 15-SP1-BCL (src):    cross-nvptx-gcc10-10.3.0+git1587-1.6.3, gcc10-10.3.0+git1587-1.6.4
SUSE Linux Enterprise Server 15-LTSS (src):    gcc10-10.3.0+git1587-1.6.4
SUSE Linux Enterprise Module for Development Tools 15-SP3 (src):    cross-nvptx-gcc10-10.3.0+git1587-1.6.3, gcc10-10.3.0+git1587-1.6.4
SUSE Linux Enterprise Module for Development Tools 15-SP2 (src):    gcc10-10.3.0+git1587-1.6.4
SUSE Linux Enterprise Module for Basesystem 15-SP3 (src):    gcc10-10.3.0+git1587-1.6.4
SUSE Linux Enterprise Module for Basesystem 15-SP2 (src):    gcc10-10.3.0+git1587-1.6.4
SUSE Linux Enterprise High Performance Computing 15-SP1-LTSS (src):    cross-nvptx-gcc10-10.3.0+git1587-1.6.3, gcc10-10.3.0+git1587-1.6.4
SUSE Linux Enterprise High Performance Computing 15-SP1-ESPOS (src):    cross-nvptx-gcc10-10.3.0+git1587-1.6.3, gcc10-10.3.0+git1587-1.6.4
SUSE Linux Enterprise High Performance Computing 15-LTSS (src):    cross-nvptx-gcc10-10.3.0+git1587-1.6.3, gcc10-10.3.0+git1587-1.6.4
SUSE Linux Enterprise High Performance Computing 15-ESPOS (src):    cross-nvptx-gcc10-10.3.0+git1587-1.6.3, gcc10-10.3.0+git1587-1.6.4
SUSE Enterprise Storage 6 (src):    cross-nvptx-gcc10-10.3.0+git1587-1.6.3, gcc10-10.3.0+git1587-1.6.4
SUSE CaaS Platform 4.0 (src):    cross-nvptx-gcc10-10.3.0+git1587-1.6.3, gcc10-10.3.0+git1587-1.6.4

NOTE: This line indicates an update has been released for the listed product(s). At times this might be only a partial fix. If you have questions please reach out to maintenance coordination.
Comment 17 Swamp Workflow Management 2021-06-07 22:17:15 UTC
openSUSE-RU-2021:0854-1: An update that has 6 recommended fixes can now be installed.

Category: recommended (moderate)
Bug References: 1029961,1106014,1178577,1178624,1178675,1182016
CVE References: 
JIRA References: 
Sources used:
openSUSE Leap 15.2 (src):    cross-nvptx-gcc10-10.3.0+git1587-lp152.5.1, gcc10-10.2.1+git583-lp152.4.1
Comment 18 Swamp Workflow Management 2021-07-09 19:26:20 UTC
openSUSE-RU-2021:1861-1: An update that has 6 recommended fixes can now be installed.

Category: recommended (moderate)
Bug References: 1029961,1106014,1178577,1178624,1178675,1182016
CVE References: 
JIRA References: 
Sources used:
openSUSE Leap 15.3 (src):    cross-aarch64-gcc10-10.3.0+git1587-1.6.3, cross-arm-gcc10-10.3.0+git1587-1.6.3, cross-hppa-gcc10-10.3.0+git1587-1.6.3, cross-i386-gcc10-10.3.0+git1587-1.6.3, cross-m68k-gcc10-10.3.0+git1587-1.6.3, cross-mips-gcc10-10.3.0+git1587-1.6.3, cross-nvptx-gcc10-10.3.0+git1587-1.6.3, cross-ppc64-gcc10-10.3.0+git1587-1.6.3, cross-ppc64le-gcc10-10.3.0+git1587-1.6.3, cross-riscv64-gcc10-10.3.0+git1587-1.6.3, cross-s390x-gcc10-10.3.0+git1587-1.6.3, cross-sparc-gcc10-10.3.0+git1587-1.6.3, cross-sparc64-gcc10-10.3.0+git1587-1.6.3, cross-x86_64-gcc10-10.3.0+git1587-1.6.3, gcc10-10.3.0+git1587-1.6.4, gcc10-testresults-10.3.0+git1587-1.6.7