This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/AM4376: Linker links against thumb instruction set when vfpu flag is set

Part Number: AM4376

Tool/software: Code Composer Studio

CCS10, PDK pdk_am437x_1_0_15. Create and app using CCS (Helloworld). Set -marm -mfloat-abi=hard -mfpu=neon and see the linker map file. It points to thumb instruction set. If the flag is set to just -marm -mfloat-abi=hard then it uses lib/hard instead of thumb. Not sure why the thumb static libraries are linked when the FPU flag is set. 

When -mfpu=neon

*startup_ARMCA9.o(.text)
*(.text*)
.text 0x80000000 0x0 c:/ti/gcc-arm-none-eabi-7-2018-q2-update/bin/../lib/gcc/arm-none-eabi/7.3.1/thumb/v7-ar/fpv3/hard/crti.o
.text 0x80000000 0x50 c:/ti/gcc-arm-none-eabi-7-2018-q2-update/bin/../lib/gcc/arm-none-eabi/7.3.1/thumb/v7-ar/fpv3/hard/crtbegin.o
.text 0x80000050 0x74 c:/ti/gcc-arm-none-eabi-7-2018-q2-update/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib/thumb/v7-ar/fpv3/hard/crt0.o
0x80000050 _start
0x80000050 _mainCRTStartup
.text 0x800000c4 0x3c8 C:/Users/akcheria/T1/__syncError/out/obj/main_A.o
0x800000c4 getCRC(unsigned char)
0x800000f8 crc32(void const*, unsigned int, unsigned long)
0x800001e8 crc32y(void const*, unsigned int, unsigned long)
0x800002cc littlemain
0x80000480 main
.text 0x8000048c 0x60 C:/Users/akcheria/T1/__syncError/out/obj/startup_ARMCA9_A.o
0x8000048c Entry
.text 0x800004ec 0x0 c:/ti/gcc-arm-none-eabi-7-2018-q2-update/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib/thumb/v7-ar/fpv3/hard\libg.a(lib_a-exit.o)
.text.exit 0x800004ec 0x20 c:/ti/gcc-arm-none-eabi-7-2018-q2-update/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib/thumb/v7-ar/fpv3/hard\libg.a(lib_a-exit.o)
0x800004ec exit

When -mfpu=neon is NOT set

.text 0x80000000 0xb4 C:/SCM/CORE/Project_Software_Eng/Code_PI/CoreACE/TargetLibs/TARG_Tx_CoreBoard/Tx_Port/out/libtx_coreboard_A.a(init.o)
0x80000000 Entry
.text 0x800000b4 0x0 c:/ti/gcc-arm-none-eabi-7-2018-q2-update/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib/hard\libstdc++_nano.a(ios_init.o)
.text 0x800000b4 0x0 c:/ti/gcc-arm-none-eabi-7-2018-q2-update/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib/hard\libstdc++_nano.a(locale_init.o)
.text 0x800000b4 0x0 c:/ti/gcc-arm-none-eabi-7-2018-q2-update/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib/hard\libstdc++_nano.a(cow-locale_init.o)
.text 0x800000b4 0x0 c:/ti/gcc-arm-none-eabi-7-2018-q2-update/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib/hard\libg.a(lib_a-init.o)

  • The output of the gcc --print-multi-lib option for gcc-arm-none-eabi-7-2018-q2-update is:

    $ bin/arm-none-eabi-gcc --print-multi-lib
    .;
    thumb;@mthumb
    hard;@mfloat-abi=hard
    thumb/v6-m;@mthumb@march=armv6s-m
    thumb/v7-m;@mthumb@march=armv7-m
    thumb/v7e-m;@mthumb@march=armv7e-m
    thumb/v7-ar;@mthumb@march=armv7
    thumb/v8-m.base;@mthumb@march=armv8-m.base
    thumb/v8-m.main;@mthumb@march=armv8-m.main
    thumb/v7e-m/fpv4-sp/softfp;@mthumb@march=armv7e-m@mfpu=fpv4-sp-d16@mfloat-abi=softfp
    thumb/v7e-m/fpv4-sp/hard;@mthumb@march=armv7e-m@mfpu=fpv4-sp-d16@mfloat-abi=hard
    thumb/v7e-m/fpv5/softfp;@mthumb@march=armv7e-m@mfpu=fpv5-d16@mfloat-abi=softfp
    thumb/v7e-m/fpv5/hard;@mthumb@march=armv7e-m@mfpu=fpv5-d16@mfloat-abi=hard
    thumb/v7-ar/fpv3/softfp;@mthumb@march=armv7@mfpu=vfpv3-d16@mfloat-abi=softfp
    thumb/v7-ar/fpv3/hard;@mthumb@march=armv7@mfpu=vfpv3-d16@mfloat-abi=hard
    thumb/v8-m.main/fpv5-sp/softfp;@mthumb@march=armv8-m.main@mfpu=fpv5-sp-d16@mfloat-abi=softfp
    thumb/v8-m.main/fpv5-sp/hard;@mthumb@march=armv8-m.main@mfpu=fpv5-sp-d16@mfloat-abi=hard

    Where the above controls how the gcc linker selects which library to link. Once a -mfpu option is used as well as -mfloat-abi=hard then the above shows a thumb static library will be linked.

    I am not sure why the supplied libraries are thumb only, but since Cortex-A9 supports ARM/thumb interworking don't believe this should cause a functional problem.

  • Does this mean if we have -mfpu option set then the code will always link to be thumb mode? This is similar to setting -mthumb right? Even when we set it to -marm? I'm not sure if this can not cause any functional problems, having thumb code when we explicitly linked with -marm? https://developer.arm.com/docs/dui0471/k/interworking-arm-and-thumb/when-to-use-interworking seems to imply tradeoffs in doing so.

  • Arun Cherian said:
    Does this mean if we have -mfpu option set then the code will always link to be thumb mode?

    It means the RTS library automatically chosen is built for thumb mode.

    Arun Cherian said:
    This is similar to setting -mthumb right?

    No.  Your code continues to be built according the build options you choose.

    Arun Cherian said:
    Even when we set it to -marm?

    Then your code is built for ARM mode.

    Arun Cherian said:
    I'm not sure if this can not cause any functional problems, having thumb code when we explicitly linked with -marm?

    It will work.  Mixing functions built with these different modes is supported.

    Arun Cherian said:

    That article advises you on how to decide which mode is best for different parts of your code.

    Thanks and regards,

    -George

  • Thanks for your response George.

    Why are thumb mode runtime libraries chosen for code that is built for ARM mode? Seems like this is happening only when -mfpu is set? If not, it seems to use regular libraries. It might work, but it this how its meant to work? Seems like its odd that setting the -mfpu flag dictates if ARM or thumb runtime libraries are linked, there seems to be no correlation?

  • I doubt there is any intentional relationship between -mfpu and the fact that the RTS library which is automatically chosen is usually built in Thumb mode.  It is probably because most of the RTS libraries supplied with the compiler are built with Thumb mode.  And that is because, it is judged that most users in most situations will prefer the RTS functions be in Thumb mode.

    Thanks and regards,

    -George