Skip to content

Commit 0935885

Browse files
committed
fix(target): add -Wl,--whole-archive linker option
1 parent 64bfabd commit 0935885

File tree

15 files changed

+34
-61
lines changed

15 files changed

+34
-61
lines changed

CMakeLists.txt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,18 @@ include_directories(include/esp-stub-lib)
5050
add_compile_definitions(${STUB_COMPILE_DEFS})
5151

5252
# Three-layer architecture:
53-
# - entry: Main stub code (src/)
54-
# - common: Generic implementations using base headers + target's soc.h + (weak functions)
55-
# - target: Target-specific code + soc.h + overrides (weak functions)
56-
# - base: Interface headers (target/*.h, private/*.h) - serves to common and target
53+
#
54+
# Layer structure and locations:
55+
# - entry: Main stub code → src/
56+
# - common: Generic implementations (weak) → src/target/common/
57+
# - target: Target-specific overrides (strong) → src/target/${ESP_TARGET}/
58+
# - base: Interface headers only → src/target/base/
5759
#
5860
# Dependency flow: entry → common → target
5961
# ↓ ↓
6062
# base base
6163

62-
add_subdirectory(src/target/base ${ESP_BASE_LIB})
63-
add_subdirectory(src/target/${ESP_TARGET} ${ESP_TARGET_LIB})
64-
add_subdirectory(src/target/common ${ESP_COMMON_LIB})
64+
add_subdirectory(src/target)
6565

66-
target_link_libraries(${ESP_TARGET_LIB} PUBLIC ${ESP_BASE_LIB})
67-
target_link_libraries(${ESP_COMMON_LIB} PUBLIC ${ESP_BASE_LIB} ${ESP_TARGET_LIB})
66+
# Link to common library (which transitively includes target and base)
6867
target_link_libraries(${ESP_STUB_LIB} PUBLIC ${ESP_COMMON_LIB})

src/target/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Parent CMakeLists for all target directories
2+
# This file contains common setup for all targets
3+
4+
# Build base (interface headers)
5+
add_subdirectory(base ${ESP_BASE_LIB})
6+
7+
# Build target-specific library
8+
add_subdirectory(${ESP_TARGET} ${ESP_TARGET_LIB})
9+
10+
# Build common library
11+
add_subdirectory(common ${ESP_COMMON_LIB})
12+
13+
# Apply common configurations to target library
14+
# This ensures strong symbols override weak ones
15+
target_link_options(${ESP_TARGET_LIB}
16+
PUBLIC -Wl,--whole-archive
17+
)
18+
19+
# Set common include directories for target library
20+
target_include_directories(${ESP_TARGET_LIB}
21+
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/${ESP_TARGET}/include
22+
)
23+
24+
# Setup dependency chain: target → base, common → base + target
25+
target_link_libraries(${ESP_TARGET_LIB} PUBLIC ${ESP_BASE_LIB})
26+
target_link_libraries(${ESP_COMMON_LIB} PUBLIC ${ESP_BASE_LIB} ${ESP_TARGET_LIB})

src/target/esp32/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ set(srcs
55

66
add_library(${ESP_TARGET_LIB} STATIC ${srcs})
77

8-
target_include_directories(${ESP_TARGET_LIB}
9-
PUBLIC include
10-
)
11-
128
target_link_options(${ESP_TARGET_LIB}
139
PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32.rom.ld
1410
PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32.rom.libc-funcs.ld

src/target/esp32c2/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ set(srcs
44

55
add_library(${ESP_TARGET_LIB} STATIC ${srcs})
66

7-
target_include_directories(${ESP_TARGET_LIB}
8-
PUBLIC include
9-
)
10-
117
target_link_options(${ESP_TARGET_LIB}
128
PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c2.rom.ld
139
PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c2.rom.api.ld

src/target/esp32c3/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ set(srcs
44

55
add_library(${ESP_TARGET_LIB} STATIC ${srcs})
66

7-
target_include_directories(${ESP_TARGET_LIB}
8-
PUBLIC include
9-
)
10-
117
target_link_options(${ESP_TARGET_LIB}
128
PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c3.rom.ld
139
PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c3.rom.api.ld

src/target/esp32c5/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ set(srcs
44

55
add_library(${ESP_TARGET_LIB} STATIC ${srcs})
66

7-
target_include_directories(${ESP_TARGET_LIB}
8-
PUBLIC include
9-
)
10-
117
target_link_options(${ESP_TARGET_LIB}
128
PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c5.rom.ld
139
PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c5.rom.api.ld

src/target/esp32c6/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ set(srcs
44

55
add_library(${ESP_TARGET_LIB} STATIC ${srcs})
66

7-
target_include_directories(${ESP_TARGET_LIB}
8-
PUBLIC include
9-
)
10-
117
target_link_options(${ESP_TARGET_LIB}
128
PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c6.rom.ld
139
PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c6.rom.api.ld

src/target/esp32c61/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ set(srcs
44

55
add_library(${ESP_TARGET_LIB} STATIC ${srcs})
66

7-
target_include_directories(${ESP_TARGET_LIB}
8-
PUBLIC include
9-
)
10-
117
target_link_options(${ESP_TARGET_LIB}
128
PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c61.rom.ld
139
PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c61.rom.api.ld

src/target/esp32h2/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ set(srcs
44

55
add_library(${ESP_TARGET_LIB} STATIC ${srcs})
66

7-
target_include_directories(${ESP_TARGET_LIB}
8-
PUBLIC include
9-
)
10-
117
target_link_options(${ESP_TARGET_LIB}
128
PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32h2.rom.ld
139
PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32h2.rom.api.ld

src/target/esp32h21/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ set(srcs
44

55
add_library(${ESP_TARGET_LIB} STATIC ${srcs})
66

7-
target_include_directories(${ESP_TARGET_LIB}
8-
PUBLIC include
9-
)
10-
117
target_link_options(${ESP_TARGET_LIB}
128
PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32h21.rom.ld
139
PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32h21.rom.api.ld

0 commit comments

Comments
 (0)