foss-for-synopsys-dwc-arc-processors / arc-gnu-toolchain

Scripting for building ARC toolchain
5 stars 3 forks source link

ARv2: Incorrect Default CPU #25

Open luismgsilva opened 1 year ago

luismgsilva commented 1 year ago

During the analysis of assembly test comparisons, several interesting observations have been made. It was previously assumed that the default CPU for ARCv2 (--target=arc) was ARCHS; however, this assumption turned out to be incorrect.

Presently, the default CPU for ARCv2 is hs38_linux CPU. This can be verified in the following GCC file: gcc/gcc/config/arc/arc.h.

# gcc/gcc/config/arc/arc.h

36     #ifndef TARGET_CPU_DEFAULT
37     #define TARGET_CPU_DEFAULT   PROCESSOR_hs38_linux
38     #endif

Although the default CPU being used is clearly hs38_linux, the information about the architecture in the generated ELF file indicates otherwise:

$ arc-elf32-readelf -A test.x
Attribute Section: ARC
File Attributes
  Tag_ARC_PCS_config: Bare metal/newlib
  Tag_ARC_CPU_base: ARCHS
  Tag_ARC_CPU_variation: Core2
  Tag_ARC_CPU_name: "archs"
  Tag_ARC_ABI_osver: v4
  Tag_ARC_ABI_sda: GNU
  Tag_ARC_ISA_config: "BITSCAN,CD,DIV_REM,FPUD,LL64,BS,SWAP"
  Tag_ARC_ISA_mpy_option: 9
  Tag_ARC_ATR_version: 1

According to the information provided by Binutils, the CPU mentioned is archs, which does not align with the actual default CPU. This discrepancy seems to be a mismatch in the information generated by Binutils.

Furthermore, there are additional discrepancies in the configuration itself. One notable difference is the behavior of the toolchain build when no CPU is specified. In this case, the FPUD (Floating-Point Unit) is enabled by default. Additionally, the Tag_ARC_ISA_mpy_option attribute is set to 9, whereas it is set to 6 when --with-cpu=archs is provided.

Please refer to the following comparisons for better understanding:

Attribute Name Default CPU Value ARCHS CPU Value
Tag_ARC_PCS_config Bare metal/newlib Bare metal/newlib
Tag_ARC_CPU_base ARCHS ARCHS
Tag_ARC_CPU_variation Core2 Core2
Tag_ARC_CPU_name "archs" "archs"
Tag_ARC_ABI_osver v4 v4
Tag_ARC_ABI_sda GNU GNU
Tag_ARC_ISA_config "BITSCAN,CD,DIV_REM,FPUD,LL64,BS,SWAP" "BITSCAN,CD,DIV_REM,LL64,BS,SWAP"
Tag_ARC_ISA_mpy_option 9 6
Tag_ARC_ATR_version 1 1
abrodkin commented 1 year ago

@luismgsilva good catch, in fact we should have fixed that discrepancy a long ago at the time we made a switch in GCC from arc700 to a fully-packed hs38_linux, see https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=46d04271a4983b5430ed4830ab65ea26052176fb (https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/issues/348, https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=989453). Moreover, I made that fix in Debian Binutils to fix exactly that discrepancy, see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=994190. But I guess it's better late than never ;)

I suggest moving that issue in the https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain as default tools settings have nothing to do with the way you build them.

claziss commented 1 year ago

A proposed fix here: https://github.com/foss-for-synopsys-dwc-arc-processors/binutils-gdb/commit/1e5b8110d5d43f1c6d21ebba5ce52924c1d20861

abrodkin commented 1 year ago

@claziss care to copy it to arc-2023.09 branch as well?