Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problems in relation to Fedora's C99 instrumentation #665

Merged
merged 2 commits into from
Sep 9, 2023

Conversation

JohnoKing
Copy link

@JohnoKing JohnoKing commented Jun 30, 2023

This pull request applies the necessary changes to the ksh codebase to (hopefully) fix C99 compilation when using Red Hat't instrumented GCC (cf. https://fedoraproject.org/wiki/Toolchain/PortingToModernC, though note that a patch to redhat-rpm-config is also required and must be applied separately, see #664 (comment)). Seeing as my previous attempt did not fully fix this problem, I would like @vmihalko to confirm that this pull request + the patch to redhat-rpm-config successfully fix the build errors that occur when building ksh with C99.

List of changes in the pull request:

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.

Note that the changes to ksh listed above do not fix all the errors. The remaining implicit function errors are caused by the incomplete exception list in redhat-rpm-config, which doesn't include the necessary functions ksh tests for. That must be fixed in redhat-rpm-config, not ksh. A patch which adds the required exceptions to the Lua script can be found in the following comment:
#664 (comment)

After applying the patch, the Lua script (which can be run via /usr/lib/rpm/redhat/report-gcc-errors.sh) will ignore the implicit function errors that are expected to occur in the feature tests, which (after fixing conf.tab and _lib_poll) should allow the build to succeed with Red Hat's instrumentation.

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 flawed 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.

Note that the changes in this commit *do not* fix all the errors.
The ones that remain are caused by the incomplete exception list in
redhat-rpm-config, which doesn't include the necessary functions
ksh tests for. That must be fixed in redhat-rpm-config, not ksh.
A patch which adds the required exceptions to the Lua script can
be found in the following comment:
ksh93#664 (comment)

After applying the patch, the Lua script (which can be run via
/usr/lib/rpm/redhat/report-gcc-errors.sh) will ignore the
implicit function errors that are expected to occur in the feature
tests, which (after fixing conf.tab and _lib_poll) should allow
the build to succeed with Red Hat's instrumentation.
@vmihalko
Copy link

vmihalko commented Jul 20, 2023

After applying the patch from #664 (comment) to redhat-rpm-config, I can confirm that the instrumented gcc did not report any errors when building ksh + this PR.

Thank you very much for all your hard work and effort!

@McDutchie
Copy link

I second that! Apologies for taking months to get around to this – real life kept having to take priority.

@McDutchie McDutchie merged commit 7f9cac3 into ksh93:dev Sep 9, 2023
McDutchie pushed a commit that referenced this pull request Sep 9, 2023
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.
@JohnoKing JohnoKing deleted the workaround-redhat-bugs branch January 5, 2024 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants