Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions recipes-ml/onnxruntime/files/0001-cmake-fix-GCC-16-build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
From 27ed4c1275586113e84d4b79b47febcef4c084d3 Mon Sep 17 00:00:00 2001
From: Koen Kooi <koen.kooi@oss.qualcomm.com>
Date: Thu, 18 Jun 2026 12:00:00 +0200
Subject: [PATCH] cmake: fix GCC 16 build (-Wmaybe-uninitialized,
-Wfree-nonheap-object)

onnxruntime 1.26.0 builds with C++20 and sets COMPILE_WARNING_AS_ERROR
ON (a bare -Werror), so two GCC 16 false-positive diagnostics become
fatal:

1) -Wmaybe-uninitialized fires in the optimizer, e.g.
matmul_nbits_fusion.cc, reading a value GCC 16 cannot prove is
initialized. onnxruntime already suppresses this for GCC 12; GCC 16
reintroduced the false positive, so extend the same guard to cover
GCC >= 16.

2) -Wfree-nonheap-object fires on std::vector destructors, e.g.
vector<graph_utils::EdgeEndToMatch> in skip_layer_norm_fusion.cc:
GCC 16 mistakes the sized-deallocation of the vector's heap storage
for a delete on an offset pointer. Disable it, gated behind
check_cxx_compiler_flag.

Upstream-Status: Pending

Signed-off-by: Koen Kooi <koen.kooi@oss.qualcomm.com>
Assisted-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---
cmake/CMakeLists.txt | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index 83d1751..22ae6cf 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -632,6 +632,8 @@ else()
check_cxx_compiler_flag(-Wambiguous-reversed-operator HAS_AMBIGUOUS_REVERSED_OPERATOR)
# -Winterference-size was added in GCC 13
check_cxx_compiler_flag(-Winterference-size HAS_INTERFERENCE_SIZE)
+ # -Wfree-nonheap-object false-positives on std::vector dtors with GCC 16
+ check_cxx_compiler_flag(-Wfree-nonheap-object HAS_FREE_NONHEAP_OBJECT)
check_cxx_compiler_flag(-Warray-bounds HAS_ARRAY_BOUNDS)
check_cxx_compiler_flag(-Wbitwise-instead-of-logical HAS_BITWISE_INSTEAD_OF_LOGICAL)
check_cxx_compiler_flag(-Wcast-function-type HAS_CAST_FUNCTION_TYPE)
@@ -721,6 +723,13 @@ else()
# Specifically, the code was tuned based on the build machine's CPU cache line size, which can vary a lot.
list(APPEND ORT_WARNING_FLAGS -Wno-interference-size)
endif()
+ if(HAS_FREE_NONHEAP_OBJECT)
+ # GCC 16 false-positives -Wfree-nonheap-object on std::vector
+ # destructors (e.g. vector<graph_utils::EdgeEndToMatch> in
+ # skip_layer_norm_fusion.cc): it mistakes the sized-deallocation of
+ # heap storage for a delete on an offset pointer.
+ list(APPEND ORT_WARNING_FLAGS -Wno-free-nonheap-object)
+ endif()
# enable warning(s) that may not be on by default
if (HAS_SHORTEN_64_TO_32)
list(APPEND ORT_WARNING_FLAGS -Wshorten-64-to-32)
@@ -1187,7 +1196,9 @@ function(onnxruntime_set_compile_flags target_name)
foreach(FLAG ${ORT_WARNING_FLAGS})
target_compile_options(${target_name} PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${FLAG}>")
endforeach()
- if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 13 AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12)
+ # GCC 12 and GCC 16 both emit false-positive -Wmaybe-uninitialized in the
+ # optimizer (e.g. matmul_nbits_fusion.cc reads a value GCC cannot prove init).
+ if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND ((CMAKE_C_COMPILER_VERSION VERSION_LESS 13 AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12) OR CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 16))
target_compile_options(${target_name} PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:-Wno-maybe-uninitialized>")
endif()
if (onnxruntime_USE_CUDA)
--
2.34.1

Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,29 @@ DEPENDS = " \
microsoft-gsl \
"

# Dependency versions and revisions are taken from cmake/deps.txt at the
# rel-1.26.0 tag. They must match what onnxruntime expects, since the build
# runs with FETCHCONTENT_FULLY_DISCONNECTED=ON.
SRC_URI = "gitsm://github.com/microsoft/onnxruntime.git;protocol=https;branch=rel-${PV};name=ort \
git://github.com/HowardHinnant/date.git;protocol=https;nobranch=1;name=date;tag=v3.0.4;destsuffix=date \
git://github.com/boostorg/mp11.git;protocol=https;nobranch=1;name=mp11;tag=boost-1.91.0;destsuffix=mp11 \
file://0001-cmake-fix-GCC-16-build.patch \
git://github.com/HowardHinnant/date.git;protocol=https;nobranch=1;name=date;tag=v3.0.1;destsuffix=date \
git://github.com/boostorg/mp11.git;protocol=https;nobranch=1;name=mp11;tag=boost-1.82.0;destsuffix=mp11 \
git://github.com/pytorch/cpuinfo.git;protocol=https;nobranch=1;name=pytorch_cpuinfo;destsuffix=pytorch_cpuinfo \
git://github.com/dcleblanc/SafeInt.git;protocol=https;nobranch=1;name=safeint;tag=3.0.28;destsuffix=safeint \
git://github.com/google/flatbuffers.git;protocol=https;nobranch=1;name=flatbuffers;tag=v23.5.26;destsuffix=flatbuffers \
git://github.com/onnx/onnx.git;protocol=https;nobranch=1;name=onnx;tag=v1.20.1;destsuffix=onnx \
git://github.com/onnx/onnx.git;protocol=https;nobranch=1;name=onnx;tag=v1.21.0;destsuffix=onnx \
git://github.com/eigen-mirror/eigen.git;protocol=https;nobranch=1;name=eigen3;destsuffix=eigen3 \
"

SRCREV_FORMAT = "ort_date_mp11_pytorch_cpuinfo_safeint_flatbuffers_onnx_eigen3"
SRCREV_ort = "470ae16099a74fe05e31f2530489332c0525edb5"
SRCREV_date = "f94b8f36c6180be0021876c4a397a054fe50c6f2"
SRCREV_mp11 = "b94b089d4ec83cd397f20958f34edf25bc3e06f4"
SRCREV_pytorch_cpuinfo = "ea6b9f1bb6e1001d8b21574d5bc78ddef62e499d"
SRCREV_ort = "8c546c37b43caaca1fa25db430dab94b901cf277"
SRCREV_date = "6e921e1b1d21e84a5c82416ba7ecd98e33a436d0"
SRCREV_mp11 = "0a0b5fb001ce0233ae3a6f99d849c0649e5a7361"
SRCREV_pytorch_cpuinfo = "403d652dca4c1046e8145950b1c0997a9f748b57"
SRCREV_safeint = "4cafc9196c4da9c817992b20f5253ef967685bf8"
SRCREV_flatbuffers = "c20d64b8de759423af61e072fcabf916c1f7bf9f"
SRCREV_onnx = "d3f6b795aedb48eaecc881bf5e8f5dd6efbe25b3"
SRCREV_eigen3 = "549bf8c75b6aae071cde2f28aa48f16ee3ae60b0"
SRCREV_onnx = "be2b5fde82d9c8874f3d19328bdfe3b6962dc67b"
SRCREV_eigen3 = "1d8b82b0740839c0de7f1242a3585e3390ff5f33"

# Fix buildpaths QA issue: remap TMPDIR references in both debug info and
# string literals embedded in the compiled libraries.
Expand All @@ -49,6 +53,7 @@ OECMAKE_SOURCEPATH = "${S}/cmake"

EXTRA_OECMAKE = " \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_CXX_STANDARD=20 \
-DCMAKE_FIND_ROOT_PATH=${STAGING_DIR_TARGET} \
-Donnxruntime_BUILD_SHARED_LIB=ON \
-DFETCHCONTENT_FULLY_DISCONNECTED=ON \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
From 158c361a47de44003ff79a3f682319eca14db252 Mon Sep 17 00:00:00 2001
From: Ricardo Salveti <ricardo.salveti@oss.qualcomm.com>
Date: Tue, 16 Jun 2026 15:36:16 +0000
Subject: [PATCH] tflite: examples: label_image: build profile_buffer.cc

The label_image example uses BufferedProfiler (via profiler.h /
buffered_profiler.h), whose EndEvent()/BeginEvent() forward to
tflite::profiling::ProfileBuffer. ProfileBuffer is declared in
profiling/profile_buffer.h and defined in profiling/profile_buffer.cc,
which is deliberately excluded from libtensorflow-lite.a
(TFLITE_PROFILER_SRCS in tensorflow/lite/CMakeLists.txt). Every tool
that pulls in the profiler must therefore compile profile_buffer.cc
itself - tools/benchmark/CMakeLists.txt already does, but the
label_image example does not.

This is a latent bug: older compilers inlined/eliminated the
out-of-line reference to ProfileBuffer::EndEvent(), but GCC 16 keeps it,
so linking label_image fails with:

undefined reference to
'tflite::profiling::ProfileBuffer::EndEvent(unsigned int,
long const*, long const*)'

Add profiling/profile_buffer.cc to TFLITE_LABEL_IMAGE_SRCS, mirroring
the benchmark_model target. Its other dependencies (time.cc,
memory_info.cc and minimal logging) are already linked, so no further
sources are needed.

Upstream-Status: Submitted [https://github.com/tensorflow/tensorflow/pull/121367]

Signed-off-by: Ricardo Salveti <ricardo.salveti@oss.qualcomm.com>
---
tensorflow/lite/examples/label_image/CMakeLists.txt | 1 +
1 file changed, 1 insertion(+)

diff --git a/tensorflow/lite/examples/label_image/CMakeLists.txt b/tensorflow/lite/examples/label_image/CMakeLists.txt
index ae4ab447064..cb9e0cbb310 100644
--- a/tensorflow/lite/examples/label_image/CMakeLists.txt
+++ b/tensorflow/lite/examples/label_image/CMakeLists.txt
@@ -25,2 +25,3 @@ list(APPEND TFLITE_LABEL_IMAGE_SRCS
${TFLITE_SOURCE_DIR}/profiling/memory_info.cc
+ ${TFLITE_SOURCE_DIR}/profiling/profile_buffer.cc
${TFLITE_SOURCE_DIR}/profiling/profile_summarizer.cc
--
2.43.0

1 change: 1 addition & 0 deletions recipes-ml/tflite/tensorflow-lite_2.20.0.bb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ SRC_URI = " \
file://tflite/0007-cmake-Fix-label-image-dependencies.patch \
file://tflite/0008-cmake-Add-install-rule-for-c-interface-shared-librar.patch \
file://tflite/0009-tflite-Add-absl-log-dependency-for-enhanced-logging-.patch \
file://tflite/0013-tflite-examples-label_image-build-profile_buffer.patch \
git://github.com/google/farmhash;name=farmhash;destsuffix=tensorflow-lite-${TF_LITE_VERSION}/third_party/farmhash/;branch=master;protocol=https \
git://github.com/google/gemmlowp.git;name=gemmlowp;destsuffix=tensorflow-lite-${TF_LITE_VERSION}/third_party/gemmlowp/;branch=master;protocol=https \
git://github.com/pytorch/cpuinfo.git;name=cpuinfo;destsuffix=tensorflow-lite-${TF_LITE_VERSION}/third_party/cpuinfo/;branch=main;protocol=https \
Expand Down
Loading