Skip to content

pwmgen: prevent GCC from emitting SSE in base-thread function#3896

Open
grandixximo wants to merge 1 commit intoLinuxCNC:masterfrom
grandixximo:fix/pwmgen-sse-base-thread
Open

pwmgen: prevent GCC from emitting SSE in base-thread function#3896
grandixximo wants to merge 1 commit intoLinuxCNC:masterfrom
grandixximo:fix/pwmgen-sse-base-thread

Conversation

@grandixximo
Copy link
Copy Markdown

make_pulses() is exported with uses_fp=0 for the base-thread, but GCC optimizes struct zeroing into SSE instructions (pxor/movups on XMM registers). Since RTAI skips FPU/SSE save/restore for non-FP threads, this silently corrupts XMM state of whatever Linux process was running, causing heap corruption, segfaults, and hard crashes.

Add attribute((target("general-regs-only"))) to make_pulses() to force GCC to use only general-purpose registers.

Confirmed via objdump that the compiled function contains zero SSE instructions after this change. Tested on RTAI 5.4.280 with the etch-servo parport config which previously crashed reliably.

See: #3895

make_pulses() is exported with uses_fp=0 for the base-thread, but GCC
optimizes struct zeroing into SSE instructions (pxor/movups on XMM
registers). Since RTAI skips FPU/SSE save/restore for non-FP threads,
this silently corrupts XMM state of whatever Linux process was running,
causing heap corruption, segfaults, and hard crashes.

Add __attribute__((target("general-regs-only"))) to make_pulses() to
force GCC to use only general-purpose registers.

Confirmed via objdump that the compiled function contains zero SSE
instructions after this change. Tested on RTAI 5.4.280 with the
etch-servo parport config which previously crashed reliably.

See: LinuxCNC#3895
@andypugh
Copy link
Copy Markdown
Collaborator

andypugh commented Apr 3, 2026

Is this fix still needed, or are we going for the meta-fix?

@grandixximo
Copy link
Copy Markdown
Author

I can work on ripping out non-FP in the weekend, this will not be needed once that is done, it is just a quick fix, if anyone wants to run RTAI with pwmgen in the meantime, Though I doubt there is anyone else but me testing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants