x86-64 Assembly Segfault on printf? Fix Stack Alignment (Yasm + GCC Demo)

4 days ago
3

Your x86-64 assembly program looks correct, links with GCC, calls printf, and then crashes with a segfault. This video shows exactly why it happens and how to fix it.

We build a hybrid program using Yasm and GCC on Linux, print a message from C++, call an assembly function, and hit the crash. Then we fix it with a push and pop of RAX, move the fix into the function prologue and epilogue, and run experiments to prove it works.

No long lectures, just code, a real crash, and a real solution that stops the problem for good.

Introduction 00:00:00
Hybrid Programs 00:00:09
Stack Alignment Problem 00:00:33
GCC Stack Expectations 00:01:14
Makefile Overview 00:02:22
Driver Code 00:03:16
Assembly Module Setup 00:04:12
Calling printf 00:05:20
Program Crash Demo 00:07:17
Diagnosing Segfault 00:07:56
Fix with Push-Pop 00:09:08
Prologue Epilogue Fix 00:11:18
Experiments Confirm 00:12:54
Conclusion 00:13:32
Outro Thanks 00:13:52

Thanks for watching!

Find us on other social media here:
- https://www.NeuralLantern.com/social

Please help support us!

- Subscribing + Sharing on Social Media
- Leaving a comment or suggestion
- Subscribing to our Blog
- Watching the main "pinned" video of this channel for offers and extras

Loading comments...