Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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().
- Loading branch information
58560db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defined(__sync_fetch_and_add)
always evaluates as false. __has_builtin should be used instead to detect GCC builtins.58560db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @JohnoKing, I will have to make that change.
Can I trust that all compilers have
__has_builtin
, or is that also a gcc-ism? If not, how would I test for the presence of__has_builtin
?58560db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should work for compilers without
__has_builtin
:58560db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Note to self: in future, read link before asking question... :P
58560db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JohnoKing : before I goof up again: does this look ok to you?
(edit: silly brokenness deleted)
58560db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will work.58560db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good, thanks for checking!58560db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait a minute, that actually will not work. All the code for
job_lock
andjob_unlock
is enclosed inif defined(__has_builtin)
. That will break with a compiler without__has_builtin
.58560db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a better version:
58560db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that just hit me as well, just before I saw your message! Thanks for the better version.
58560db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done a little more research on
__has_builtin
. It looks like gcc didn't add it until very recently... in GCC 10, in May 2019!Given the age of the segfault reports, this makes it look rather unlikely that any gcc version with
__has_builtin
actually has this optimiser bug... surely, wrongly optimising out something rudimentary like a unary increase operator would have been spotted by now?Absent
__has_builtin
on older gcc versions, the only way to test for a builtin is by adding aniffe
test. I don't know howiffe
works, I don't want to invest the time to learn how it works, and I don't see anyone else volunteering to add such a test any time soon.So now I'm inclined to simply revert the patch instead (and waste your work, sorry about that). What do you think?
58560db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize only GCC 10 has
__has_builtin
. Reverting the patch should be fine (for now). I'll see if I can find a different fix that doesn't rely on GCC-specific features.