fix(simulator): build v4l2_capture as position-independent code - #144
Merged
Conversation
kern_simulator links with -pie, but the v4l2_capture static library was compiled without -fPIC. On toolchains where GCC is not configured with --enable-default-pie (e.g. Fedora 44), linking with -DSIM_WEBCAM=ON fails: relocation R_X86_64_32 against `.rodata` can not be used when making a PIE object; recompile with -fPIE A static archive is linked object-by-object into the executable, so its relocations must be compatible with a PIR output. The lvgl and wally targets already set POSITION_INDEPENDENT_CODE; v4l2_capture was added later and did not. On Debian/Ubuntu the objects were position independent by compiler default, which masked the problem. Simulator-only change: it does not touch any device code path.
Owner
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The desktop simulator fails to link with
-DSIM_WEBCAM=ONon toolchains where GCC is not configured with--enable-default-pie(reproduced on Fedora 44, GCC 16.1.1):kern_simulatoris linked with-pie(intentional hardening - the simulator parses untrusted input). A static archive is linked object-by-object into the executable, so objects compiled without-fPICcannot be used.v4l2_captuedid not setPOSITION_INDEPENDENT_CODE, so its.textcarried 15 absoluteR_X86_64_PC32.The
lvglandwallytargets already set this property;v4l2_capturewas added later and did not. On Debian/Ubuntu, GCC defaults to PIE, so the objects were position independent by accident and the bug stayed hidden.Change
One line: set
POSITION_INDEPENDENT_CODE ONon thev4l2_capturetarget, matching whatlvglandwallyalready do. Placed after theif(APPLE)/else()block so it covers both the V4L2 and AVFoundation variants.Testing
cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug -DSIM_WEBCAM=ON+ build: links successfully (previously failed).SIM_WEBCAM: unaffected.ctest:storage_smokepasses.Impact
Simulator build system only. No device code path, no firmware build, no change to the simulator/firmware separation. Hardening flags (
-pie,relro,now,noexecstack) are preserved. This makes the build honor than weakening them.