Provide 32-bit enums with the GCC linker

I am writing a bare metal application for an ARM device (no OS). I need a 32 bit enum, so I compiled the app with a flag -fno-short-enums

. Without this flag, I get the enum variables (and forcing the size by adding an extra value 0xFFFFFFFF

for each enum is not an option).

Now I get the following linker warning for each object:

c:/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: ./src/test.o uses 32-bit enums yet the output is to use variable-size enums; use of enum values across objects may fail

      

This is just a warning, no error. But what does this mean? How can I specify "exit"?

I tried to recompile newlib with the above checkbox to ensure that all objects use the same enum size, but I still get a warning. Am I missing something?

+4


source to share


2 answers


After a while, everything worked for me. I have rebuilt the entire toolbox including the compiler with this flag. This is how I did it:

  1. Get the toolbox source from https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads

  2. Add 3 lines to some sections of buildscript build-toolchain.sh

    :

    saveenv
    saveenvvar CFLAGS_FOR_TARGET '-fno-short-enums'
      [...build commands...]
    restoreenv
    
          

    Modified sections:

    • Task [III-1]/$HOST_NATIVE/gcc-first/

    • Task [III-2]/$HOST_NATIVE/newlib/

    • Task [III-4]/$HOST_NATIVE/gcc-final/

    • Task [IV-3]/$HOST_MINGW/gcc-final/

    I gcc-size-libstdcxx

    newlib-nano

    and gcc-size-libstdcxx

    .

  3. Run the modified scripts build-prerequisites.sh

    and build-toolchain.sh

    to collect everything.


After that, the compiler uses large enumeration mode, and the linker is fine with my objects. But now I get the opposite of a warning for some objects newlib ( lib_a-mbtowc_r.o

, lib_a-svfiprintf.o

, lib_a-svfprintf.o

, lib_a-vfprintf.o

and lib_a-vfiprintf.o

):



c:/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: c:/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/lib\libc.a(lib_a-mbtowc_r.o) uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail

      

I looked in the makefiles of these objects, and unfortunately they are explicitly set to size-enum variables. The only "solution" for this was to add a linker flag to disable this warning:

-Xlinker -no-enum-size-warning

      

It.

+1


source


I have a partial answer as I had the same question. The problem is the linker warning that will show up using -fno-short-enums. The message indicates that the target is incompatible. So I spent a whole world of time trying to change the goal to be compatible.

But it's not a problem. By default the gcc compiler will generate 32-bit enums! Thus, this parameter is not needed unless you MUST want 32-bit enums. However, if you specify -fno-short-enums, you get a warning message. Unfortunately, I don't know why.



So the bottom line is that the no-short-enums flag is not needed to achieve 32-bit enums. If you specify it, you will receive a warning message.

+2


source







All Articles