Skip to content

Commit

Permalink
Fix problems in relation to Fedora's C99 instrumentation (#665)
Browse files Browse the repository at this point in the history
This commit applies the necessary changes to the ksh codebase to
fix C99 compilation when using Red Hat's instrumented GCC[*],
though note that a patch to redhat-rpm-config is also required and
must be applied separately[*2].

[*1] https://fedoraproject.org/wiki/Toolchain/PortingToModernC
[*2] #664 (comment)

src/lib/libast/comp/conf.tab:
- Add include directives to fix implicit function declarations that
  cause the PID_MAX test to silently fail. This compile error
  occurs on all platforms when compiling with strict C99, but
  wasn't exposed even after setting IFFEFLAGS to -d1 or -d2 (that's
  likely a separate bug in conf.sh that'll need fixing). As a
  consequence, it could cause following bug in the getconf builtin
  (now fixed as of this commit):
    $ /opt/ast/bin/getconf PID_MAX
    30000  # Wrong, should be the platform value (e.g., 4194304)

src/lib/libast/{features/lib,sfio/sfhdr.h}:
- Delete the lib_poll_fd_2 feature test and associated code, which
  allowed ksh to used non-compliant implementations of poll(3).
  This feature test fails on POSIX-compliant systems with
  int-conversion errors, which is the expected result. However, the
  C99 instrumentation used by Red Hat marks the entire build as a
  failure because of the fact those errors exist at all, even
  though the build proceeds as normal. Fortunately, the operating
  systems supported by ksh (AFAIK) all have proper, POSIX-compliant
  versions of poll() and thus don't need this test. To work around
  the flawed instrumentation, the unnecessary test has been
  jettisoned.
  • Loading branch information
JohnoKing committed Sep 9, 2023
1 parent aa6dc48 commit 7f9cac3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 32 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.
- Fixed incorrect rejection of the tab key while reading input using the `read`
built-in command. Bugs introduced on 2021-02-26 (emacs) and 2022-08-24 (vi).

- Fixed a minor bug that could cause '/opt/ast/bin/getconf PID_MAX' to
return the wrong value when ksh is built with strict C99.

2023-06-13:

- Fixed a serious regression in pathname expansion where quoted wildcard
Expand Down
3 changes: 3 additions & 0 deletions src/lib/libast/comp/conf.tab
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ PBS_MESSAGE POSIX SC 2 FUW
PBS_TRACK POSIX SC 2 FUW
PHYS_PAGES SUN SC 1 0
PID_MAX SVID SC 1 LMU 30000 cc{
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
long v;
Expand Down
24 changes: 1 addition & 23 deletions src/lib/libast/features/lib
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ tst tst_errno note{ errno can be assigned }end link{
int main(void) { errno = 0; error(); strerror(); return 0; }
}end

tst lib_poll_fd_1 note{ fd is first arg to poll() }end execute{
tst lib_poll note{ poll() args comply with the POSIX standard }end execute{
#include <poll.h>
#include <unistd.h>
extern int pipe(int*);
Expand All @@ -87,28 +87,6 @@ tst lib_poll_fd_1 note{ fd is first arg to poll() }end execute{
}
}end

tst lib_poll_fd_2 note{ fd is second arg to poll() }end execute{
#include <poll.h>
#include <unistd.h>
extern int pipe(int*);
int
main(void)
{ int rw[2];
struct pollfd fd;
if (pipe(rw) < 0) return 1;
fd.fd = rw[0];
fd.events = POLLIN;
fd.revents = 0;
return poll(1, &fd, 0) < 0;
if (poll(1, &fd, 0) < 0 || fd.revents != 0) return 1;
if (write(rw[1], "x", 1) != 1) return 1;
if (poll(1, &fd, 0) < 0 || fd.revents == 0) return 1;
return 0;
}
}end

exp _lib_poll _lib_poll_fd_1||_lib_poll_fd_2

tst lib_poll_notimer note{ poll with no fds ignores timeout }end execute{
#include <sys/types.h>
#include <poll.h>
Expand Down
9 changes: 0 additions & 9 deletions src/lib/libast/sfio/sfhdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,12 @@
#if _sys_select
#include <sys/select.h>
#endif
#else
#if _lib_poll_fd_1 || _lib_poll_fd_2
#define _lib_poll 1
#endif
#endif /*_lib_select_*/

#if _lib_poll
#include <poll.h>

#if _lib_poll_fd_1
#define SFPOLL(pfd,n,tm) poll((pfd),(ulong)(n),(tm))
#else
#define SFPOLL(pfd,n,tm) poll((ulong)(n),(pfd),(tm))
#endif
#endif /*_lib_poll*/

#if _stream_peek
#include <stropts.h>
Expand Down

0 comments on commit 7f9cac3

Please sign in to comment.