Win16: build without -fno-threadsafe-statics

The guard of a function-local static calls __atomic_load_1. The i8086
compiler-rt builtins have it (i8086/atomic.c), so the flag is not
necessary. The link error came from a sysroot with older builtins.

- Remove the flag from the Win16 build and the Win16 test script.
- win16wnd tests a function-local static object.
- docs/win16.md says what to do with an older sysroot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRRTV4u8c9f3gQUmqvq
This commit is contained in:
Claude committed 2026-11-25 13:41:40 +00:00
1 parent 1a0b5d69b8
commit 595b23b462
4 files changed
+18 -7

No files matched your search

+1 -1
View File
@@ -94,7 +94,7 @@ SRCS = $(addprefix src/,object.cpp strcore.cpp coll.cpp file.cpp archive.cpp exc
viewedit.cpp viewprnt.cpp \
viewprev.cpp)
WIN16_FLAGS ?= -mcmodel=large -fexceptions
ALL_CXXFLAGS += $(WIN16_FLAGS) -frtti -fno-threadsafe-statics -ffunction-sections \
ALL_CXXFLAGS += $(WIN16_FLAGS) -frtti -ffunction-sections \
-Iinclude/win16 -idirafter port/include
STDLIB =
endif
+6 -4
View File
@@ -75,7 +75,7 @@ Use these flags:
```sh
clang++ --target=i8086-pc-win16 -mcmodel=large -fexceptions -frtti \
-fno-threadsafe-statics --sysroot=/path/to/sysroot \
--sysroot=/path/to/sysroot \
-Ipath/to/mfc/include -Ipath/to/mfc/include/win16 \
-idirafter path/to/mfc/port/include \
app.cpp app.res -Lpath/to/mfc/build/i8086-pc-win16 -lmfc -o app.exe
@@ -85,9 +85,11 @@ clang++ --target=i8086-pc-win16 -mcmodel=large -fexceptions -frtti \
headers send the OLE names to the OLE 2 headers of the 16-bit SDK.
- `-idirafter port/include` must come last. The SDK has no common
control headers. The headers of the portable layer give their types.
- `-fno-threadsafe-statics` is necessary. A function-local static
object otherwise needs `__atomic_load_1`, which the 16-bit libraries
do not have. A task has one thread, so the guard is not necessary.
- The guard of a function-local static object calls `__atomic_load_1`.
The compiler-rt builtins of the sysroot have this function
(`compiler-rt/lib/builtins/i8086/atomic.c`). A sysroot that does not
have it is too old: build its builtins again. A task has one thread,
so `-fno-threadsafe-statics` is safe, and it makes the program smaller.
- Compile the resources with `llvm-rc -win16`.
A program with `main()` and the core classes only can use `-mquickwin`,
+1 -1
View File
@@ -25,7 +25,7 @@ fi
T=$OUT/tests
mkdir -p "$T"
CXX="$BIN/clang++ --target=i8086-pc-win16 -mcmodel=large -fexceptions -frtti -fno-threadsafe-statics"
CXX="$BIN/clang++ --target=i8086-pc-win16 -mcmodel=large -fexceptions -frtti"
CXX="$CXX --sysroot=$SYSROOT -Iinclude -Iinclude/win16 -idirafter port/include -Itests"
LIBS="-L$OUT -lmfc"
npass=0
+10 -1
View File
@@ -2,7 +2,8 @@
// CFrameWnd with a message map, a menu command, a button notification,
// WM_CTLCOLOR from a static control, timers, and a modal CDialog from a
// resource with DDX. It prints ALL PASSED when each step worked, because
// Wine gives the exit code 0 whatever a 16-bit program returns.
// Wine gives the exit code 0 whatever a 16-bit program returns. A
// function-local static object tests the guard (__atomic_load_1).
#include <afxwin.h>
#include <stdio.h>
#include "win16wnd.h"
@@ -41,6 +42,12 @@ protected:
}
};
/// Gives a string that is made on the first call only.
static const CString& StaticName() {
static CString s_strName("static name");
return s_strName;
}
class CMainFrame : public CFrameWnd {
public:
BOOL m_bCreated;
@@ -126,6 +133,8 @@ protected:
CHECK(pApp->GetProfileInt("Test", "Value", 0) == 1234);
CHECK(pApp->WriteProfileString("Test", "Name", "win16"));
CHECK(pApp->GetProfileString("Test", "Name") == "win16");
CHECK(StaticName() == "static name");
CHECK(&StaticName() == &StaticName());
g_bDone = TRUE;
DestroyWindow();
break;