espressif / ESP8266_RTOS_SDK

Latest ESP8266 SDK based on FreeRTOS, esp-idf style.
http://bbs.espressif.com
Apache License 2.0
3.35k stars 1.57k forks source link

Linking fails on hello_world example with disabled assertions (GIT8266O-836) #1260

Open klew opened 1 year ago

klew commented 1 year ago

Environment

Problem Description

I would like to get rid of file paths from my local PC in "bin" file. I thought this was caused by logging assertions, so I tried to silent assertions, but paths were still in bin file. Then I disabled assertions by setting:

CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y

However this breaks linking with following error:

App "hello-world" version: v3.4-87-g3b15c065-dirty
esptool.py v2.4.0
.flash.rodata len 0x02c08 load 0x4021cfc0

A fatal error occurred: Segment loaded at 0x4021cfc0 lands in same 64KB flash mapping as segment loaded at 0x40210010. Can't generate binary. Suggest changing linker script or ELF to merge sections.

Expected Behavior

hello_world example should compile and link with disabled assertions.

Actual Behavior

Linking fails when assertions are disabled.

Steps to repropduce

  1. go to hello_world example
  2. run: make menuconfig and in "Compiler options" set assertion level to "disabled"
  3. run: make

Here is output from objdump:

~/esp/ESP8266_RTOS_SDK/examples/get-started/hello_world$ xtensa-lx106-elf-objdump -h build/hello-world.elf 

build/hello-world.elf:     file format elf32-xtensa-le

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .rtc_noinit   00000000  60001200  60001200  00015bc8  2**0
                  CONTENTS
  1 .iram0.vectors 00000080  40100000  40100000  00002000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .iram0.text   00003e44  40100080  40100080  00002080  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  3 .iram0.bss    00000208  40103ec4  40103ec4  00005ec4  2**2
                  ALLOC
  4 .dram0.data   00000370  3ffe8000  3ffe8000  00001000  2**4
                  CONTENTS, ALLOC, LOAD, DATA
  5 .noinit       00000000  3ffe8370  3ffe8370  00015bc8  2**0
                  CONTENTS
  6 .dram0.bss    00001310  3ffe8370  3ffe8370  00001370  2**4
                  ALLOC
  7 .flash.text   0000cfae  40210010  40210010  00006010  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  8 .flash.rodata 00002c08  4021cfc0  4021cfc0  00012fc0  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  9 .debug_frame  000059dc  00000000  00000000  00015bc8  2**2
                  CONTENTS, READONLY, DEBUGGING
 10 .debug_info   0006764e  00000000  00000000  0001b5a4  2**0
                  CONTENTS, READONLY, DEBUGGING
 11 .debug_abbrev 00010d6e  00000000  00000000  00082bf2  2**0
                  CONTENTS, READONLY, DEBUGGING
 12 .debug_loc    0002047a  00000000  00000000  00093960  2**0
                  CONTENTS, READONLY, DEBUGGING
 13 .debug_aranges 00001bf0  00000000  00000000  000b3de0  2**3
                  CONTENTS, READONLY, DEBUGGING
 14 .debug_ranges 00003030  00000000  00000000  000b59d0  2**3
                  CONTENTS, READONLY, DEBUGGING
 15 .debug_line   000383e4  00000000  00000000  000b8a00  2**0
                  CONTENTS, READONLY, DEBUGGING
 16 .debug_str    0000e45f  00000000  00000000  000f0de4  2**0
                  CONTENTS, READONLY, DEBUGGING
 17 .comment      000000c7  00000000  00000000  000ff243  2**0
                  CONTENTS, READONLY
 18 .xtensa.info  00000038  00000000  00000000  000ff30a  2**0
                  CONTENTS, READONLY
 19 .xt.lit._ZNK9__gnu_cxx24__concurrence_lock_error4whatEv 00000008  00000000  00000000  000ff342  2**0
                  CONTENTS, READONLY
 20 .xt.lit._ZNK9__gnu_cxx26__concurrence_unlock_error4whatEv 00000008  00000000  00000000  000ff34a  2**0
                  CONTENTS, READONLY
 21 .xt.lit._ZN9__gnu_cxx24__concurrence_lock_errorD5Ev 00000008  00000000  00000000  000ff352  2**0
                  CONTENTS, READONLY
 22 .xt.lit._ZN9__gnu_cxx26__concurrence_unlock_errorD5Ev 00000008  00000000  00000000  000ff35a  2**0
                  CONTENTS, READONLY
 23 .xt.lit._ZN9__gnu_cxx7__mutex4lockEv 00000008  00000000  00000000  000ff362  2**0
                  CONTENTS, READONLY
 24 .xt.lit._ZN9__gnu_cxx13__scoped_lockD5Ev 00000008  00000000  00000000  000ff36a  2**0
                  CONTENTS, READONLY
 25 .xt.prop._ZNK9__gnu_cxx24__concurrence_lock_error4whatEv 00000030  00000000  00000000  000ff372  2**0
                  CONTENTS, READONLY
 26 .xt.prop._ZNK9__gnu_cxx26__concurrence_unlock_error4whatEv 00000030  00000000  00000000  000ff3a2  2**0
                  CONTENTS, READONLY
 27 .xt.prop._ZN9__gnu_cxx24__concurrence_lock_errorD5Ev 0000000c  00000000  00000000  000ff3d2  2**0
                  CONTENTS, READONLY
 28 .xt.prop._ZN9__gnu_cxx26__concurrence_unlock_errorD5Ev 0000000c  00000000  00000000  000ff3de  2**0
                  CONTENTS, READONLY
 29 .xt.prop._ZN9__gnu_cxx7__mutex4lockEv 00000030  00000000  00000000  000ff3ea  2**0
                  CONTENTS, READONLY
 30 .xt.prop._ZN9__gnu_cxx13__scoped_lockD5Ev 0000000c  00000000  00000000  000ff41a  2**0
                  CONTENTS, READONLY
 31 .xt.prop._ZN9__gnu_cxx24__concurrence_lock_errorD2Ev 00000024  00000000  00000000  000ff426  2**0
                  CONTENTS, READONLY
 32 .xt.prop._ZN9__gnu_cxx26__concurrence_unlock_errorD2Ev 00000024  00000000  00000000  000ff44a  2**0
                  CONTENTS, READONLY
 33 .xt.prop._ZN9__gnu_cxx24__concurrence_lock_errorD0Ev 00000024  00000000  00000000  000ff46e  2**0
                  CONTENTS, READONLY
 34 .xt.prop._ZN9__gnu_cxx26__concurrence_unlock_errorD0Ev 00000024  00000000  00000000  000ff492  2**0
                  CONTENTS, READONLY
 35 .xt.prop._ZN9__gnu_cxx13__scoped_lockD2Ev 00000048  00000000  00000000  000ff4b6  2**0
                  CONTENTS, READONLY
 36 .xt.prop._ZTIN9__gnu_cxx24__concurrence_lock_errorE 0000000c  00000000  00000000  000ff4fe  2**0
                  CONTENTS, READONLY
 37 .xt.prop._ZTIN9__gnu_cxx26__concurrence_unlock_errorE 0000000c  00000000  00000000  000ff50a  2**0
                  CONTENTS, READONLY
 38 .xt.prop._ZTVN9__gnu_cxx24__concurrence_lock_errorE 0000000c  00000000  00000000  000ff516  2**0
                  CONTENTS, READONLY
 39 .xt.prop._ZTVN9__gnu_cxx26__concurrence_unlock_errorE 0000000c  00000000  00000000  000ff522  2**0
                  CONTENTS, READONLY
 40 .xt.prop._ZTISt9exception 0000000c  00000000  00000000  000ff52e  2**0
                  CONTENTS, READONLY
 41 .xt.prop._ZTISt13bad_exception 0000000c  00000000  00000000  000ff53a  2**0
                  CONTENTS, READONLY
 42 .xt.prop._ZTIN10__cxxabiv115__forced_unwindE 0000000c  00000000  00000000  000ff546  2**0
                  CONTENTS, READONLY
 43 .xt.prop._ZTIN10__cxxabiv119__foreign_exceptionE 0000000c  00000000  00000000  000ff552  2**0
                  CONTENTS, READONLY
 44 .xt.prop._ZTVSt13bad_exception 0000000c  00000000  00000000  000ff55e  2**0
                  CONTENTS, READONLY
 45 .xt.prop._ZTIN10__cxxabiv120__si_class_type_infoE 0000000c  00000000  00000000  000ff56a  2**0
                  CONTENTS, READONLY
 46 .xt.prop._ZTVN10__cxxabiv120__si_class_type_infoE 0000000c  00000000  00000000  000ff576  2**0
                  CONTENTS, READONLY
 47 .xt.prop._ZTIN10__cxxabiv117__class_type_infoE 0000000c  00000000  00000000  000ff582  2**0
                  CONTENTS, READONLY
 48 .xt.prop._ZTVN10__cxxabiv117__class_type_infoE 0000000c  00000000  00000000  000ff58e  2**0
                  CONTENTS, READONLY
 49 .xt.prop._ZTISt9type_info 0000000c  00000000  00000000  000ff59a  2**0
                  CONTENTS, READONLY
 50 .xt.lit._ZNK9__gnu_cxx29__concurrence_broadcast_error4whatEv 00000008  00000000  00000000  000ff5a6  2**0
                  CONTENTS, READONLY
 51 .xt.lit._ZNK9__gnu_cxx24__concurrence_wait_error4whatEv 00000008  00000000  00000000  000ff5ae  2**0
                  CONTENTS, READONLY
 52 .xt.lit._ZN9__gnu_cxx24__concurrence_wait_errorD5Ev 00000008  00000000  00000000  000ff5b6  2**0
                  CONTENTS, READONLY
 53 .xt.lit._ZN9__gnu_cxx29__concurrence_broadcast_errorD5Ev 00000008  00000000  00000000  000ff5be  2**0
                  CONTENTS, READONLY
 54 .xt.lit._ZN9__gnu_cxx6__cond9broadcastEv 00000008  00000000  00000000  000ff5c6  2**0
                  CONTENTS, READONLY
 55 .xt.prop._ZNK9__gnu_cxx29__concurrence_broadcast_error4whatEv 00000030  00000000  00000000  000ff5ce  2**0
                  CONTENTS, READONLY
 56 .xt.prop._ZNK9__gnu_cxx24__concurrence_wait_error4whatEv 00000030  00000000  00000000  000ff5fe  2**0
                  CONTENTS, READONLY
 57 .xt.prop._ZN9__gnu_cxx24__concurrence_wait_errorD5Ev 0000000c  00000000  00000000  000ff62e  2**0
                  CONTENTS, READONLY
 58 .xt.prop._ZN9__gnu_cxx29__concurrence_broadcast_errorD5Ev 0000000c  00000000  00000000  000ff63a  2**0
                  CONTENTS, READONLY
 59 .xt.prop._ZN9__gnu_cxx6__cond9broadcastEv 00000030  00000000  00000000  000ff646  2**0
                  CONTENTS, READONLY
 60 .xt.prop._ZN9__gnu_cxx24__concurrence_wait_errorD2Ev 00000024  00000000  00000000  000ff676  2**0
                  CONTENTS, READONLY
 61 .xt.prop._ZN9__gnu_cxx29__concurrence_broadcast_errorD2Ev 00000024  00000000  00000000  000ff69a  2**0
                  CONTENTS, READONLY
 62 .xt.prop._ZN9__gnu_cxx24__concurrence_wait_errorD0Ev 00000024  00000000  00000000  000ff6be  2**0
                  CONTENTS, READONLY
 63 .xt.prop._ZN9__gnu_cxx29__concurrence_broadcast_errorD0Ev 00000024  00000000  00000000  000ff6e2  2**0
                  CONTENTS, READONLY
 64 .xt.prop._ZTIN9__gnu_cxx29__concurrence_broadcast_errorE 0000000c  00000000  00000000  000ff706  2**0
                  CONTENTS, READONLY
 65 .xt.prop._ZTIN9__gnu_cxx24__concurrence_wait_errorE 0000000c  00000000  00000000  000ff712  2**0
                  CONTENTS, READONLY
 66 .xt.prop._ZTVN9__gnu_cxx29__concurrence_broadcast_errorE 0000000c  00000000  00000000  000ff71e  2**0
                  CONTENTS, READONLY
 67 .xt.prop._ZTVN9__gnu_cxx24__concurrence_wait_errorE 0000000c  00000000  00000000  000ff72a  2**0
                  CONTENTS, READONLY
klew commented 1 year ago

It looks like there are two sections: .flash.text and .flash.rodata which "start" should be in different 64 KB flash region. Disabling asserts is reducing text section to very small one ( < 64 KB) and it causes above linking error. For some reason, it is not a problem for linker if text and rodata share the same sector when text length is > 64 KB.

Anyway linking problem can be resolved by adding ALIGN(64K) to text section, as follows:

diff --git a/components/esp8266/ld/esp8266.project.ld.in b/components/esp8266/ld/esp8266.project.ld.in
index 54d7bb48..ce1decc2 100644
--- a/components/esp8266/ld/esp8266.project.ld.in
+++ b/components/esp8266/ld/esp8266.project.ld.in
@@ -175,6 +175,7 @@ SECTIONS
     *(.fini.literal)
     *(.fini)
     *(.gnu.version)
+    . = ALIGN (64K);
     _text_end = ABSOLUTE(.);
     _etext = .;

It fixes linking but it make binary file a little bit bigger. I'm not very familiar with ldgen, so if there is away to add this align conditionally, then it would be better solution.