Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reducing the size of .rodata

Tags:

I'm crosscompiling C++ in Gentoo for an ARM Cortex M3 (Maple Mini), but seem to have hit a roof with the memory resources when linking the elf-file

/usr/libexec/gcc/arm-none-eabi/ld: build/maple_mini.elf section `.rodata' will not fit in region `rom'
/usr/libexec/gcc/arm-none-eabi/ld: region `rom' overflowed by 1508 bytes

This post is a question about how to reduce the size of the contents of .rodata, to be able to complete the linking of the elf-file.

I have stripped the included code, and am compiling with the following relevant options.

CXXFLAGS = -fno-rtti -fno-exceptions -Os -fdata-sections -ffunction-sections -Wl,-gc-sections ...
LDFLAGS = -Wl,-gc-sections -fno-exceptions -fno-rtti ...

Still, the .rodata in the map-file (with which I am quite unfamiliar) contains what seems to be some kind of type information for each of the classes in the program. Some map-file excerpts (note. MPU6050 is a SuperSensor<> which is a Sensor<>, in a C++ sense)

    0x000000000801d6c0       0x28 .../libsyrup.a(MPU6050.o)
    0x000000000801d6c0    _ZTVN5syrup6SensorILi6EEE
.rodata._ZTVN5syrup11SuperSensorILi6EEE    0x000000000801d6e8       0x28 .../libsyrup.a(MPU6050.o)
    0x000000000801d6e8                _ZTVN5syrup11SuperSensorILi6EEE
.rodata._ZTVN5syrup7MPU6050E  0x000000000801d710       0x28 .../libsyrup.a(MPU6050.o)
     0x000000000801d710                _ZTVN5syrup7MPU6050E
.rodata._ZTVN5syrup6SensorILi1EEE
     0x000000000801d738                 0x28 .../libsyrup.a(MS5611.o)
     0x000000000801d738                _ZTVN5syrup6SensorILi1EEE
.rodata._ZTVN5syrup11SuperSensorILi1EEE
            0x000000000801d760          0x28 .../libsyrup.a(MS5611.o)
            0x000000000801d760                _ZTVN5syrup11SuperSensorILi1EEE
...
            0x000000000801ee24          0x6f3 .../libstdc++.a(cp-demangle.o)
                                        0x730 (size before relaxing)
*fill*         0x000000000801f517       0x1 
.rodata        0x000000000801f518       0x14 .../libgcc.a(unwind-arm.o)
.rodata        0x000000000801f52c       0x23c .../libc.a(lib_a-strerror.o)
.rodata.str1.4    0x000000000801f768    0x635 .../libc.a(lib_a-strerror.o)
                                        0x63c (size before relaxing)

So, lib_a-strerror.o and cp-demangle.o seems to be what takes up most space, although I guess these are quite vital.

So, my question is, what further steps can I take to reduce (or restructure the code) the .rodata section, and what exactly is stored there? Any suggestions are welcome! I am fairly new to the deeper workings of compilation and linking, but learning.