Linker issues? const appears multiple times in rodata.

coratron
Posts: 4
Joined: Mon Dec 07, 2020 3:42 am

Linker issues? const appears multiple times in rodata.

Postby coratron » Sat May 01, 2021 1:28 pm

Hi all,

I have posted this on the platformio forums but thought it made perhaps more sense here.

We have been working on a project for quite a while now and we just recently discovered that the compiled binary seems to contain several copies of some variables.

We are using the widely used OLED library for SSD1306 displays :

https://github.com/ThingPulse/esp8266-oled-ssd1306

The repeated elements in the memory are the fonts. Here is what the beginning of the font file looks like:

Code: Select all

#ifndef OLEDDISPLAYFONTS_h
#define OLEDDISPLAYFONTS_h

const uint8_t ArialMT_Plain_10[] PROGMEM = {
  0x0A, // Width: 10
  0x0D, // Height: 13
  0x20, // First Char: 32
  0xE0, // Numbers of Chars: 224

  // Jump Table:
  0xFF, 0xFF, 0x00, 0x03,  // 32:65535
  0x00, 0x00, 0x04, 0x03,  // 33:0
  0x00, 0x04, 0x05, 0x04,  // 34:4
  0x00, 0x09, 0x09, 0x06,  // 35:9
  0x00, 0x12, 0x0A, 0x06,  // 36:18
  0x00, 0x1C, 0x10, 0x09,  // 37:28
  0x00, 0x2C, 0x0E, 0x07,  // 38:44
  0x00, 0x3A, 0x01, 0x02,  // 39:58
I found out by using the Inspect tool of PlatformIO and confirmed it by using binwalk on the binary from a terminal to check if it contained the initial bytes of the fonts. It does have them; binwalk returns the exact same number of results as the font appears on the results of the Inspect tool.

This is chewing quite a bit of flash. Why would this be happening? What is the solution?

Thank you

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Linker issues? const appears multiple times in rodata.

Postby ESP_Sprite » Thu May 06, 2021 8:34 am

Do you include this file in multiple C files? If so, can be that each individual compilation unit gets its own copy, yeah. A solution is to put the data in a .c file, and only have the 'extern' declaration in the header.

coratron
Posts: 4
Joined: Mon Dec 07, 2020 3:42 am

Re: Linker issues? const appears multiple times in rodata.

Postby coratron » Tue May 18, 2021 1:38 am

Thanks @ESP_Sprite , that was the issue.

I am familiar with this approach for exposing variables across multiple files. I am not sure why it did not occur to me to try it before. Thanks for the observation.

Problem solved.

Who is online

Users browsing this forum: PepeTheGreat and 60 guests