LTO and EABI enum size

Asked by Bobby Moretti

Hi,

I am trying to partially link a project into a single object file, that I will later archive into a static library. The object file needs to be linked against code generated with full-sized enums.

I am passing -fno-short-enums when compiling all object files.

I'd like to enable link-time optimization while performing the partial link step.

If I build the project with -flto, then the output file has the Tag_ABI_enum_size = small elf attribute. Leaving out -flto is enough to get a Tag_ABI_enum_size = int attribute.

I was able to boil the issue down to a minimal example. I have two trivial source files

obj1.cc:

    int x(int y)
    {
        return y - 10;
    }

obj2.cc:

    int foo(int bar)
    {
        return bar*10;
    }

and I compile each source file using

    $ arm-none-eabi-g++.exe -fno-short-enums -mcpu=arm946e-s -c obj1.cc -o obj1.o -Os -flto -nostdlib
    $ arm-none-eabi-g++.exe -fno-short-enums -mcpu=arm946e-s -c obj2.cc -o obj2.o -Os -flto -nostdlib

If I link them without -flto, link time optimization is not invoked, and I get an object file marked as having int-sized enums:

    $ arm-none-eabi-g++.exe -fno-short-enums -mcpu=arm946e-s obj1.cc obj2.cc -Wl,-Ur -o partial_link_result.o -nostdlib -Os
    $ arm-none-eabi-readelf.exe -a partial_link_result.o | grep enum
      Tag_ABI_enum_size: int

But if I simply add -flto to the linker invocation, the output claims that it has small enums:

    $ arm-none-eabi-g++.exe -fno-short-enums -mcpu=arm946e-s obj1.cc obj2.cc -Wl,-Ur -o partial_link_result.o -nostdlib -Os -flto
    $ arm-none-eabi-readelf.exe -a partial_link_result.o | grep enum
      Tag_ABI_enum_size: small

If I run the link step with `-v`, I can see this when gcc gets to the lto stage:

Thread model: single
gcc version 4.8.3 20140228 (release) [ARM/embedded-4_8-branch revision 208322] (GNU Tools for ARM Embedded Processors)
COLLECT_GCC_OPTIONS='-c' '-fexceptions' '-mcpu=arm946e-s' '-mcpu=arm946e-s' '-nostdlib' '-Os' '-v' '-dumpdir' './' '-dumpbase' 'partial_link_result.o.ltrans0' '-fltrans' '-o' '/tmp/ccOd77GF.ltrans0.ltrans.o'
 /usr/bin/../lib/gcc/arm-none-eabi/4.8.3/lto1 -quiet -dumpdir ./ -dumpbase partial_link_result.o.ltrans0 -mcpu=arm946e-s -mcpu=arm946e-s -auxbase-strip /tmp/ccOd77GF.ltrans0.ltrans.o -Os -version -fexceptions -fltrans @/tmp/ccCixY4J -o /tmp/ccnQeRsb.s

It sure looks to me like something removed `-fno-short-enums` from `COLLECT_GCC_OPTIONS` during the LTO step. I have reproduced the same behavior on several different gcc 4.8 distributions (Mentor's Sourcery 4.8.1, Ubuntu's 4.8.2, and now the gcc-arm-embedded 4.8.3).

Is this a bug? How can I use gcc's link-time optimization while generating code without short enums?

Thanks,
Bobby

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Joey Ye (jinyun-ye) said :
#1

Bobby,

Thanks much reporting this issue, which feels like a bug to me.

Please give us some time to confirm it.

- Joey

Revision history for this message
Bobby Moretti (bobmoretti) said :
#2

Thanks for looking into the issue. Please let me know if you need any more information from me.

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#3

As explained in https://bugs.launchpad.net/gcc-arm-embedded/+bug/1315810 , this bug has been fixed upstream.