Skip to content

Fix for compiling on AIX using IBM XLC compiler#42

Closed
MrShark wants to merge 1 commit intocr-marcstevens:masterfrom
MrShark:AIX-XLC-fix
Closed

Fix for compiling on AIX using IBM XLC compiler#42
MrShark wants to merge 1 commit intocr-marcstevens:masterfrom
MrShark:AIX-XLC-fix

Conversation

@MrShark
Copy link

@MrShark MrShark commented May 9, 2018

Building on AIX using XLC gives an error during make test:
Error: Compiled for incorrect endianness
This also breaks in git from 2.13.2

Add a #ifdef guard based on macros defined at [2] and [3].

Should perhaps xlc should should be changed to or combined with _AIX
based on the behavour of GCC on AIX or XL C on Linux.

  1. git/git@6b851e5
  2. https://www.ibm.com/support/knowledgecenter/SSGH2K_13.1.3/com.ibm.xlc1313.aix.doc/compiler_ref/macros_platform.html
  3. https://www.ibm.com/support/knowledgecenter/SSGH2K_13.1.3/com.ibm.xlc1313.aix.doc/compiler_ref/xlmacros.html

Building on AIX using XLC gives an error during make test:
Error: Compiled for incorrect endianness
This also breaks in git from 2.13.2

Add a #ifdef guard based on macros defined at [2] and [3].

Should perhaps __xlc__ should should be changed to or combined with _AIX
based on the behavour of GCC on AIX or XL C on Linux.

1. git/git@6b851e5
2. https://www.ibm.com/support/knowledgecenter/SSGH2K_13.1.3/com.ibm.xlc1313.aix.doc/compiler_ref/macros_platform.html
3. https://www.ibm.com/support/knowledgecenter/SSGH2K_13.1.3/com.ibm.xlc1313.aix.doc/compiler_ref/xlmacros.html
@jrn
Copy link

jrn commented May 9, 2018

#elif (defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || \
defined(__sparc))
defined(__sparc) || (defined(__powerpc) && defined(__xlc__)))
Copy link

Choose a reason for hiding this comment

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

As I discussed in more detail at https://public-inbox.org/git/20180509183008.GL10348@aiede.svl.corp.google.com/, I think the intent behind this defined(__powerpc) is closer to defined(_BIG_ENDIAN).

Copy link

Choose a reason for hiding this comment

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

Before committing this, please see also: #40.

I think perhaps testing for _BIG_ENDIAN might be what we're after? I used this patch on MacPorts https://github.com/kencu/macports-ports/blob/0261b9a80b537020f07b58831c2b5eb44404a27a/devel/git/files/patch-sha1dc-older-apple-gcc-versions.diff but perhaps it is too machine-specific as well.

Copy link
Collaborator

@shumow shumow May 12, 2018

Choose a reason for hiding this comment

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

@kencu I am more inclined to this change here, as it continues the solution that we have been using.

@MrShark Do you have an opinion on Ken's comment?

Copy link

@kencu kencu May 12, 2018

Choose a reason for hiding this comment

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

OK -- but I was thinking that then no sooner would that be committed than we'd need another one right after like:

(defined(__ppc__) && defined(__APPLE__))

and I was hoping we might cover off all of them with a

defined(_BIG_ENDIAN)

instead, as that would seem to include everyone in one fell swoop without causing any troubles that I can forsee...

Copy link
Author

Choose a reason for hiding this comment

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

I have no big options about the solutions, any is fine with me. But I can confirm that a patch like below also works for AIX with xlc:

diff --git a/lib/sha1.c b/lib/sha1.c
index 25eded1..b30988e 100644
--- a/lib/sha1.c
+++ b/lib/sha1.c
@@ -84,7 +84,7 @@
 /* Not under GCC-alike or glibc or *BSD or newlib */
 #elif (defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
        defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || \
-       defined(__sparc))
+       defined(__sparc) || defined(_BIG_ENDIAN))
 /*
  * Should define Big Endian for a whitelist of known processors. See
  * https://sourceforge.net/p/predef/wiki/Endianness/ and

Copy link
Owner

@cr-marcstevens cr-marcstevens May 16, 2018

Choose a reason for hiding this comment

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

Yes, you're probably right. Endianness detection remains ugly stuff.
The problem indeed is that even for little endian machines a BIG_ENDIAN macro may be defined, and vice versa.
Although I don't know if we tried this logic: if defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN) to avoid that problem.

I was still hoping there might be a more general and simpler solution than whitelisting platforms,
but what we have works and adding another whitelisting should cause no problems if it is specific enough.
Alright, so let's go for this approach that doesn't cause problems for other people.

Copy link
Owner

Choose a reason for hiding this comment

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

BTW the original issue mentioned that this broke git.
Didn't git have its own endianness detection that overrules our own?

Copy link

@kencu kencu May 16, 2018

Choose a reason for hiding this comment

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

Apparently not - at least, it broke git on some of my machines. On certain system versions, however, Apple machines use a different SHA1 method (Apple Common Crypto) so they weren't affected.

Would you like me to make up another PR for the Apple tests?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would you like me to make up another PR for the Apple tests?
@kencu Yes please.

Copy link

@aixtools aixtools Jul 30, 2018

Choose a reason for hiding this comment

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

I 'discovered' this independently - while trying to build the latest git.

As this is 'for AIX' and AIX is only BigEndian the simple define to check is simply '_AIX'.

When it is "Linux on Power" I would suggest looking in /proc/... somewhere. I do not have a system handy, but there is file/directory with the current operational mode (as POWER can run in either mode - iirc the 'boot' process tells the processor which endian mode it needs.

@aixtools
Copy link

aixtools commented Jul 31, 2018

This is not "AIX" related, but POWER related. Maybe the title should/cound be changed to "Fix when compiling on POWER".

a) POWER7 and earlier are Big Endian only
b) POWER8 and later support both modes

With Debian (on POWER6) I could not find anything useful in /proc/{powerppc|ppc64|ppc64el|ppc64le}/{rtas|lparcfg}

However the output of lscpu is useful:

root@x074:/usr/bin# lscpu | grep -i endian
Byte Order:            Big Endian

Again, AIX is always Big Endian.

Looking at a gcc compiler I have for "defines" it looks again asif _AIX is the thing to test:

root@x068:[/data/httpd/gcc]gcc -dM -E - < /dev/null | grep AIX
#define _AIX 1
#define _AIX32 1
#define _AIX41 1
#define _AIX43 1
#define _AIX51 1
#define _AIX52 1
#define _AIX53 1

While xlc, in /etc/vacx.cfg.{53|61|71|72} has:

michael@x071:[/home/michael]/usr/bin/grep -p DEFLT: /etc/vac* | grep options\
        options   = -D_AIX,-D_AIX32,-D_AIX41,-D_AIX43,-D_AIX50,-D_AIX51,-D_AIX52,-D_AIX53,-D_IBMR2,-D_POWER
        options   = -D_AIX,-D_AIX32,-D_AIX41,-D_AIX43,-D_AIX50,-D_AIX51,-D_AIX52,-D_AIX53,-D_AIX61,-D_IBMR2,-D_POWER
        options   = -D_AIX,-D_AIX32,-D_AIX41,-D_AIX43,-D_AIX50,-D_AIX51,-D_AIX52,-D_AIX53,-D_AIX61,-D_AIX71,-D_IBMR2,-D_POWER
        options   = -D_AIX,-D_AIX32,-D_AIX41,-D_AIX43,-D_AIX50,-D_AIX51,-D_AIX52,-D_AIX53,-D_AIX61,-D_AIX71,-D_AIX72,-D_IBMR2,-D_POWER

@kencu
Copy link

kencu commented Aug 2, 2018

This PR is now redundant given #45, so it might as well be closed.

I may open up another PR at some point for the Apple PPC systems, but that is fixed now with a MacPorts patch anyway so not in any way particularly urgent.

@avar
Copy link
Contributor

avar commented Aug 2, 2018

@kencu : Do you have a link to that MacPorts patch?

avar added a commit to avar/git that referenced this pull request Aug 2, 2018
Update sha1dc from the latest version by the upstream
maintainer[1]. See 2db8732 ("Merge branch 'ab/sha1dc'", 2017-07-10)
for the last update.

This fixes an issue where AIX was wrongly detected as a Little-endian
instead of a Big-endian system. See [2][3][4].

1. cr-marcstevens/sha1collisiondetection@232357e
2. cr-marcstevens/sha1collisiondetection#45
3. cr-marcstevens/sha1collisiondetection#42
4. https://public-inbox.org/git/20180729200623.GF945730@genre.crustytoothpaste.net/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
gitster pushed a commit to git/git that referenced this pull request Aug 2, 2018
Update sha1dc from the latest version by the upstream
maintainer[1]. See 2db8732 ("Merge branch 'ab/sha1dc'", 2017-07-10)
for the last update.

This fixes an issue where AIX was wrongly detected as a Little-endian
instead of a Big-endian system. See [2][3][4].

1. cr-marcstevens/sha1collisiondetection@232357e
2. cr-marcstevens/sha1collisiondetection#45
3. cr-marcstevens/sha1collisiondetection#42
4. https://public-inbox.org/git/20180729200623.GF945730@genre.crustytoothpaste.net/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
@kencu
Copy link

kencu commented Sep 12, 2018

@MrShark
Copy link
Author

MrShark commented Jul 23, 2024

Cleaning up among my old pull requests, I no longer have access to AIX systems to test this out on and since it seems soved in #45.

@MrShark MrShark closed this Jul 23, 2024
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.

7 participants