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

Restore XCODE5 build #6226

Merged
merged 7 commits into from
Sep 27, 2024
Merged

Restore XCODE5 build #6226

merged 7 commits into from
Sep 27, 2024

Conversation

mikebeaton
Copy link
Contributor

@mikebeaton mikebeaton commented Sep 20, 2024

Description

Drifts in EDK 2, submodules and Xcode itself mean the XCODE5 toolchain currently does not build out-of-the-box.

The changes required to fix this are small, and are included in this sequence of commits.

It should not be hard to achieve CI as well, but some quick experiments show that because I do not control https://dev.azure.com/tianocore/edk2-ci, nor mu_nasm nor mu_iasl, that I believe that as a contributor I cannot set up working CI (it may be possible to fake it by overriding settings in existing CI).

  • Breaking change?
  • Impacts security?
  • Includes tests?

How This Was Tested

Build and run OVMF on XCODE5 (multiple versions and various -D options), and on Linux (multiple toolchains), locally. Also confirm building and running under existing CI for existing toolchains.

Integration Instructions

N/A

@mdkinney
Copy link
Member

There are 6 commits in this PR with only 2 of them related to the change. Looks like it may need to be rebased.

Also, the changes to the BEGIN/END macros need to consider that that the use of the macro is followed by a ';'. The expansion of the macro needs to consider this and make sure there are no compiler error/warnings for an extra ';' or a missing statement. These macros have not been modified in a very long time, so the issues related to the ';' may not be present in the currently supported compilers.

@mikebeaton
Copy link
Contributor Author

I meant there to be 6 commits. Each of these 6 issues breaks the XCODE5 build, and the commit fixes it (albeit that some of the others are ostensibly 'wrong' and need fixing anyway, the other toolchains do not complain and XCODE5 does).

As regards the macro expansion, I did not write it (though ofc I've offered it as I believe it's correct), I don't know if @mhaeuser has any time to comment?

@mdkinney
Copy link
Member

I agree all 6 commits are required. All good updates. do see multiple Signed-off-by. Could this be changed to single Signed-off-by and Co-authored-by tags?

I looked at git history. The style of BEGIN()/END() has not changed since imported 17 years ago. I seem to recall the addition of the extra local variable was done to support the ';' at the end of the macro usage. Perhaps removing the extra do loop and just ending with the local variable being set to FALSE would be a more compatible change and address the compiler warning.

@mikebeaton
Copy link
Contributor Author

mikebeaton commented Sep 20, 2024

As regards the macro expansion, I did not write it (though ofc I've offered it as I believe it's correct), I don't know if @mhaeuser has any time to comment?

I looked at git history. The style of BEGIN()/END() has not changed since imported 17 years ago. I seem to recall the addition of the extra local variable was done to support the ';' at the end of the macro usage. Perhaps removing the extra do loop and just ending with the local variable being set to FALSE would be a more compatible change and address the compiler warning.

Perhaps I can add: it's my belief that the ; handling is already correct; from the comment in the relevant commit, the local variable is more to ensure matched BEGIN and END than to ensure support for ;; I guess that the reason the definition hasn't changed for 17 years is that nothing complained about this before, but I think the XCODE5 compiler's complaint about the current code is probably valid, and that the replacement code has the same effect, but without a 'set but unused' error (i.e. we can 'compile away' what does happen, but it's not a case of a set but unused variable).

EDIT: Reading the code carefully, prompted by your comment, I don't think there is an extra do loop, though it looks like it. The outer do loop is the standard idiom for a macro to end safely with respect to following semicolons, as required. That's unchanged. The inner do loop is new, but it's required as part of the fix to what's happening inside the outer do loop; and also looking at it carefully, I believe cannot be combined with the outer do loop (basically because https://stackoverflow.com/q/32334338).

@mdkinney
Copy link
Member

If we want to go for the simplest form of these macros with formatting added to increase readability it would be:

#define DEBUG_CODE_BEGIN()      \
  do {                          \
    if (DebugCodeEnabled ()) {

#define DEBUG_CODE_END()  \
    }                     \
  } while (FALSE)

In this form, if DEBUG_CODE_BEGIN() is used without a ; at the end of the statement, it will still build. If the ; is missing at the end of a DEBUG_CODE_END() statement, then the build will fail for a missing semicolon. I think the original comment is misleading. I think the intent of the extra local variable is to catch use of DEBUG_CODE_BEGIN() with a missing ; at the end of the statement. By adding a local variable declaration, if the ; is missing, a compiler error will result.

We we need is a form that will generate compiler error if ; is missing and is compatible with XCODE.

@mhaeuser
Copy link
Member

@mdkinney Thanks for clearing that up! This actually makes a lot of sense. Yet, the parity behaviour I described applies as well - even if unintentionally at first - and I don't think this should be regressed upon. As such, I suggest to add some no-op statement like (VOID) __DebugCodeLocal to require the terminating ;, but to keep the double loops for the parity property.

This is part of a sequence of commits to restore build on the XCODE5
toolchain.

The definition is required on other toolchains, but on XCODE5 results
in a macro redefined error (from the existing value 255) from
/usr/include/stdint.h.

Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
@mikebeaton mikebeaton marked this pull request as draft September 21, 2024 07:03
mikebeaton and others added 5 commits September 21, 2024 08:06
Without these changes, we get the error:

  error: variable '__DebugCodeLocal' set but not used

from the DebugLib.h DEBUG_CODE_BEGIN()/END() macros on XCODE5.

Similarly, in NOOPT builds only, we get:

  error: variable '__PerformanceCodeLocal' set but not used

from the PerformanceLib.h PERF_CODE_BEGIN()/END() macros on XCODE5.

It is important to note that the previous code involving a local
variable was intended to ensure correct behaviour of ; following
the macros, in particular that ; should be required:
 - tianocore#6226 (comment)
 - tianocore#6226 (comment)
This converted version repeats the
standard do { ... } while (FALSE) idiom (which is already used in
the END macro) to achieve the same affect.

The modified versions work on all toolchains.

Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
Without this change we get:

  error: equality comparison with extraneous parentheses

when building on XCODE5.

Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
REF: https://edk2.groups.io/g/devel/message/88179

Without this change, we get:

  fatal error: 'Availability.h' file not found

when building on XCODE5.

The workaround uses a define present in openssl/include/crypto/rand.h
which modifies openssl behaviour on Apple only, causing the library
to default to a non-system specific source of entropy in syscall_random()
in rand_unix.c.

Co-authored-by: Savva Mitrofanov <savvamtr@gmail.com>
Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
Without this change we get:

  error: variable 'Index' set but not used

when building on XCODE5.

Co-authored-by: Savva Mitrofanov <savvamtr@gmail.com>
Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
Without this change we get:

  error: equality comparison with extraneous parentheses

when building with -D NETWORK_IP6_ENABLE on XCODE5.

Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
@mikebeaton
Copy link
Contributor Author

mikebeaton commented Sep 21, 2024

@mdkinney - Many thanks for your input on this PR. I've redone the DEBUG_CODE and PERF_CODE macros in a new way, avoiding the local variable entirely. I think it looks sane and safe, and addresses what you raised. It compiles and runs correctly on XCODE5 and under CI. I've also switched to Co-authored-by: tags as requested.

@mikebeaton mikebeaton marked this pull request as draft September 21, 2024 07:18
@mikebeaton mikebeaton marked this pull request as ready for review September 21, 2024 07:30
@mdkinney
Copy link
Member

Thanks for the updates. This version looks much cleaner than the original.

Copy link
Contributor

@liyi77 liyi77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CryptoPkg part looks good to me.

@mdkinney mdkinney added the push Auto push patch series in PR if all checks pass label Sep 27, 2024
@mergify mergify bot merged commit 8b295e0 into tianocore:master Sep 27, 2024
126 checks passed
mergify bot pushed a commit that referenced this pull request Sep 27, 2024
Without these changes, we get the error:

  error: variable '__DebugCodeLocal' set but not used

from the DebugLib.h DEBUG_CODE_BEGIN()/END() macros on XCODE5.

Similarly, in NOOPT builds only, we get:

  error: variable '__PerformanceCodeLocal' set but not used

from the PerformanceLib.h PERF_CODE_BEGIN()/END() macros on XCODE5.

It is important to note that the previous code involving a local
variable was intended to ensure correct behaviour of ; following
the macros, in particular that ; should be required:
 - #6226 (comment)
 - #6226 (comment)
This converted version repeats the
standard do { ... } while (FALSE) idiom (which is already used in
the END macro) to achieve the same affect.

The modified versions work on all toolchains.

Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
push Auto push patch series in PR if all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants