Skip to content

Commit 9207001

Browse files
authored
pico2: link executorch_core after kernel libs to fix --whole-archive resolution (#19163)
### Summary The Pico2 firmware link fails with an undefined reference to BoxedEvalueList<std::optional<Tensor>>::get() from RegisterCodegenUnboxedKernelsEverything.cpp.obj inside libportable_ops_lib.a. ld walks the link line once: by the time --whole-archive pulls the codegen TU's reference into the link, libexecutorch_core.a (which contains the evalue.cpp specialization) has already been processed. Pico2 was green until #18962 (TOB-EXECUTORCH-31 fix), which removed EValue::~EValue's inline call to BoxedEvalueList::get(). Before that commit, libexecutorch_core.a had its own use of the symbol that forced evalue.cpp.o to be pulled early; the link-order bug was always latent and the destructor change unmasked it. Move libexecutorch_core.a to after the kernel archives in all four USE_CMSIS_NN x USE_SELECTIVE_BUILD branches so the codegen TUs can still resolve their references after --whole-archive. Authored with Claude. ### Test plan CI
1 parent 0852840 commit 9207001

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

examples/raspberry_pi/pico2/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,31 +144,35 @@ if(USE_CMSIS_NN)
144144
# CMSIS-NN model uses only cortex_m:: ops, no portable ops needed. Skip
145145
# --whole-archive on portable_ops_lib to avoid pulling unused ops.
146146
message(STATUS "Selective build: CMSIS-NN only (no portable ops)")
147+
# libexecutorch_core.a is listed after the kernel libs so that any
148+
# references introduced by --whole-archive (e.g. EValue accessors used by
149+
# the codegen-generated kernel registrations) can still pull in symbols from
150+
# evalue.cpp. ld walks the link line once, left to right.
147151
target_link_libraries(
148152
executorch_pico
149153
PRIVATE ${BAREMETAL_BUILD_DIR}/lib/libexecutorch.a
150-
${BAREMETAL_BUILD_DIR}/lib/libexecutorch_core.a
151154
-Wl,--whole-archive
152155
${BAREMETAL_BUILD_DIR}/lib/libcortex_m_ops_lib.a
153156
-Wl,--no-whole-archive
154157
${BAREMETAL_BUILD_DIR}/lib/libcortex_m_kernels.a
155158
${BAREMETAL_BUILD_DIR}/lib/libportable_kernels.a
156159
${BAREMETAL_BUILD_DIR}/lib/libcmsis-nn.a
160+
${BAREMETAL_BUILD_DIR}/lib/libexecutorch_core.a
157161
pico_stdlib
158162
pico_stdio_usb
159163
)
160164
else()
161165
target_link_libraries(
162166
executorch_pico
163167
PRIVATE ${BAREMETAL_BUILD_DIR}/lib/libexecutorch.a
164-
${BAREMETAL_BUILD_DIR}/lib/libexecutorch_core.a
165168
-Wl,--whole-archive
166169
${BAREMETAL_BUILD_DIR}/lib/libcortex_m_ops_lib.a
167170
${BAREMETAL_BUILD_DIR}/lib/libportable_ops_lib.a
168171
-Wl,--no-whole-archive
169172
${BAREMETAL_BUILD_DIR}/lib/libcortex_m_kernels.a
170173
${BAREMETAL_BUILD_DIR}/lib/libportable_kernels.a
171174
${BAREMETAL_BUILD_DIR}/lib/libcmsis-nn.a
175+
${BAREMETAL_BUILD_DIR}/lib/libexecutorch_core.a
172176
pico_stdlib
173177
pico_stdio_usb
174178
)
@@ -179,23 +183,23 @@ else()
179183
target_link_libraries(
180184
executorch_pico
181185
PRIVATE ${BAREMETAL_BUILD_DIR}/lib/libexecutorch.a
182-
${BAREMETAL_BUILD_DIR}/lib/libexecutorch_core.a
183186
-Wl,--whole-archive
184187
${BAREMETAL_BUILD_DIR}/lib/libexecutorch_selected_kernels.a
185188
-Wl,--no-whole-archive
186189
${BAREMETAL_BUILD_DIR}/lib/libportable_kernels.a
190+
${BAREMETAL_BUILD_DIR}/lib/libexecutorch_core.a
187191
pico_stdlib
188192
pico_stdio_usb
189193
)
190194
else()
191195
target_link_libraries(
192196
executorch_pico
193197
PRIVATE ${BAREMETAL_BUILD_DIR}/lib/libexecutorch.a
194-
${BAREMETAL_BUILD_DIR}/lib/libexecutorch_core.a
195198
-Wl,--whole-archive
196199
${BAREMETAL_BUILD_DIR}/lib/libportable_ops_lib.a
197200
-Wl,--no-whole-archive
198201
${BAREMETAL_BUILD_DIR}/lib/libportable_kernels.a
202+
${BAREMETAL_BUILD_DIR}/lib/libexecutorch_core.a
199203
pico_stdlib
200204
pico_stdio_usb
201205
)

0 commit comments

Comments
 (0)