Comments (5)
This old System V/386 code uses 4 byte stack alignment (i.e. stack pointer is incremented and decremented in multiples of 4 bytes).
We're linking it dynamically to libc and ncurses. If host libc and ncurses use some SSE instructions in their compiled code (which will be the case on all modern mainstream OSs), these instructions expect 16 byte stack alignment.
The old System V/386 code might leave the stack aligned to a multiple of 4 bytes that's not a multiple of 16 bytes at some point before jumping into glibc or ncurses, which will cause a segfault.
There are a couple ways to make this old code work on a modern system:
-
use
-mstackrealign
when compiling libc and ncurses for the system123elf
will run on. Some distributions do this for 32-bit versions of libraries. This flag will make the compiler generate extended function prologues and epilogues that will check stack alignment on each function call and allign it to 16 bytes if necessary. -
statically link
123elf
with versions of libc and ncurses that were either compiled (a) without instructions that require 16 byte alignment (and so are fine with 4 byte aligned stack),, e.g.-march=i386
or (b) with-mstackrealign
. While statically linking against glibc seems to be generally discouraged, as glibc might still dynamicallydlopen
some shared objects, it is possible that the subset of libc functionality needed by123elf
might be safe.
from 123elf.
Recompiling 32-bit glibc with -mstackrealign
solved the issue for me. I found some pointers on this here and here.
This glibc stack alignment issue might be worth mentioning in the README.
It might also be worth adding -ltinfo
to LDLIBS
in the Makefile.
from 123elf.
It might also be worth adding
-ltinfo
toLDLIBS
in the Makefile.
It may depend on how ncurses was compiled (even in Gentoo depending on USE flags), I just changed the line to use pkg-config:
LDLIBS := $(shell pkg-config --libs ncurses)
-mstackrealign did the trick, I did have to add it to 32bit CFLAGS for both glibc and ncurses (adding it only to glibc showed a later segfault in ncurses)
% cat /etc/portage/package.env/32bitstackalign
sys-libs/glibc 32bitstackalign.conf
sys-libs/ncurses 32bitstackalign.conf
% cat /etc/portage/env/32bitstackalign.conf
CFLAGS_x86="${CFLAGS_x86} -mstackrealign"
CXXFLAGS_x86="${CXXFLAGS_x86} -mstackrealign"
from 123elf.
Does this still reproduce?
I'm not sure if I should add -mstackrealign, or if this can only be changed by recompiling ncurses?
from 123elf.
Thanks for the discussion, I think I'll close this bug for now and we'll discuss if we should provide a statically linked binary in #76.
from 123elf.
Related Issues (20)
- Investigate SIGWINCH handler HOT 4
- Macro / step not visible HOT 6
- BREAK Function & NUM Indicator are Disabled HOT 3
- Exploitable Stack Overflow HOT 6
- Add LICENSE HOT 3
- Segmentation fault (core dumped) HOT 5
- 'Ctrl-Z' Forces Exit to terminal losing all data HOT 6
- Exiting graph display from within a macro HOT 3
- Adding a Data Legend can mess up the graph display. HOT 1
- Math Error HOT 9
- Wiki: How to enter a formula that starts with a cell reference? HOT 2
- lotus123r3_1.0-4bionic_i386.deb does not install on 32bit system HOT 1
- Installation gets errors while extracting files HOT 6
- PIC files? HOT 4
- Appreciation; signal handling issues; typo in linux/unix flags translation? HOT 8
- Function status missing range name HOT 5
- Not a source port?
- Linux Debian 12 Bookworm Launched
- Make /File Import use a larger buffer
- Not working in fbterm HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from 123elf.