Skip to content

Commit 58560db

Browse files
committed
Restore build without __sync_fetch_and_{add,sub} (re: 07cc71b)
The more I think about it, the more it seems obvious that commit 07cc71b (PR #14) is quite simply a workaround for a GCC optimiser bug, and (who knows?) possibly an old, long-fixed one, as the bug report is years old. The commit also caused ksh to fail to build on HP-UX B.11.11 with GCC 4.2.3 (hosted at polarhome.com), because it doesn't have __sync_fetch_and_add() and __sync_fetch_and_sub(). It may fail on other systems. The GCC documentation says these are legacy: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html HELP WANTED: what I would like best is if someone could come up with some way of detecting this optimiser bug and then error out with a message along the lines of "please upgrade your broken compiler". It would probably need to be a new iffe test. Meanwhile, let's try it this way for a while and see what happens: src/cmd/ksh93/include/jobs.h: - Restore original ksh version of job_lock()/job_unlock() macros. - Use the workaround version only if the compiler has the builtins __sync_fetch_and_add() and __sync_fetch_and_sub().
1 parent f95d310 commit 58560db

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

TODO

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Fix regression test failures:
99
______
1010
Fix build system:
1111

12-
- ksh does not currently build on NetBSD, AIX, HP-UX, Solaris, or QNX.
12+
- ksh does not currently build on NetBSD, AIX, Solaris, or QNX.
1313
- Reimport the removed nmake. It is necessary for changes in Makefiles
1414
to take effect. The machine-generated Mamfiles are now used as a fallback,
1515
but they are not meant to be edited by hand.

src/cmd/ksh93/include/jobs.h

+25-1
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,17 @@ extern struct jobs job;
149149
#define vmbusy() 0
150150
#endif
151151

152+
/*
153+
* Job locking and unlocking macros
154+
*/
155+
#if defined(__sync_fetch_and_add) && defined(__sync_fetch_and_sub)
156+
/*
157+
* This version may prevent segfaults due to a GCC optimizer bug.
158+
* See: https://bugzilla.redhat.com/show_bug.cgi?id=1112306
159+
* https://bugs.launchpad.net/ubuntu/+source/ksh/+bug/1697501
160+
*/
152161
#define asoincint(p) __sync_fetch_and_add(p,1)
153162
#define asodecint(p) __sync_fetch_and_sub(p,1)
154-
155163
#define job_lock() asoincint(&job.in_critical)
156164
#define job_unlock() \
157165
do { \
@@ -163,6 +171,22 @@ extern struct jobs job;
163171
asodecint(&job.in_critical); \
164172
} \
165173
} while(0)
174+
#else
175+
/*
176+
* Original ksh93 version.
177+
*/
178+
#define job_lock() (job.in_critical++)
179+
#define job_unlock() \
180+
do { \
181+
int sig; \
182+
if (!--job.in_critical && (sig = job.savesig)) \
183+
{ \
184+
if (!job.in_critical++ && !vmbusy()) \
185+
job_reap(sig); \
186+
job.in_critical--; \
187+
} \
188+
} while(0)
189+
#endif /* defined(__sync_fetch_and_add) && defined(__sync_fetch_and_sub) */
166190

167191
extern const char e_jobusage[];
168192
extern const char e_done[];

0 commit comments

Comments
 (0)