Bug 574931 - [mac aarch64] x86_64 binaries get placed in ~/.swt/lib/macosx/aarch64 folder
Summary: [mac aarch64] x86_64 binaries get placed in ~/.swt/lib/macosx/aarch64 folder
Status: CLOSED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.20   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 572797
  Show dependency tree
 
Reported: 2021-07-20 13:49 EDT by Ned Twigg CLA
Modified: 2021-11-26 04:32 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ned Twigg CLA 2021-07-20 13:49:50 EDT
I have been developing with SWT 4.20 since it was released. My dev machine is an M1 Macbook, and I have been using Rosetta to run an x86_64 JVM and use all x86_64 native dependencies.

Today, for the first time, I downloaded the `aarch64` build of SWT and tried to use that. At runtime, I got the error message `mach-o, but wrong architecture`.

After some googling, I ran the following command:

```
user@machine> lipo ~/.swt/lib/macosx/aarch64/libswt-cocoa-4944r26.jnilib
Non-fat file: /Users/user/.swt/lib/macosx/aarch64/libswt-cocoa-4944r26.jnilib is architecture: x86_64
```

I backed-up the .swt directory (`mv ~/.swt ~/.swt-backup`) and then it worked. Now:

```
user@machine> lipo ~/.swt/lib/macosx/aarch64/libswt-cocoa-4944r26.jnilib
Non-fat file: /Users/ntwigg/.swt/lib/macosx/aarch64/libswt-cocoa-4944r26.jnilib is architecture: arm64
```

I think what's happening is that the SWT jar is unpacking itself based on the *native* architecture, rather than the *running* architecture. So if you run the x86_64 SWT jar under Rosetta on an M1 macbook, it will extract itself to the `aarch64` directory and now you can't use `aarch64` on that machine until you delete the `.swt` directory.

Fwiw, one way to detect the native architecture is this:
https://github.com/diffplug/durian-swt/blob/5ad2dbb8e980065baff53eb1399b62c6fb12a646/durian-swt.os/src/main/java/com/diffplug/common/swt/os/OS.java#L110-L116

As distinct from the running architecture:
https://github.com/diffplug/durian-swt/blob/5ad2dbb8e980065baff53eb1399b62c6fb12a646/durian-swt.os/src/main/java/com/diffplug/common/swt/os/OS.java#L177-L178
Comment 1 Lakshmi P Shanmugam CLA 2021-10-26 11:54:22 EDT
(In reply to Ned Twigg from comment #0)``
> 
> I think what's happening is that the SWT jar is unpacking itself based on
> the *native* architecture, rather than the *running* architecture. So if you
> run the x86_64 SWT jar under Rosetta on an M1 macbook, it will extract
> itself to the `aarch64` directory and now you can't use `aarch64` on that
> machine until you delete the `.swt` directory.
> 

SWT gets the running architecture and not the native architecture using System.getProperty("os.arch") similar to your example. 

Please see the code here --> https://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/bundles/org.eclipse.swt/Eclipse%20SWT%20PI/common/org/eclipse/swt/internal/Library.java#n67

So, running with a native aarch64 JVM is expected to return aarch64 and x86_64 JVM should return x86_64. 
Is it not working as expected? I don't have access to an arm64 machine now to verify the exact use case which is not working.
Comment 2 Niraj Modi CLA 2021-11-26 04:23:33 EST
Works for me: We have verified this problem and it doesn't happen when correct JVM and SWT jar combination is used.

Problem happens when there is a mis-match architecture of JRE and SWT used:
for example when you are using aarch64 JRE with X86_64 SWT library combination, which causes this error.

Closing this bug for now, can you please verify this your side ?
Comment 3 Niraj Modi CLA 2021-11-26 04:32:57 EST
Thanks Ned for providing the machine for testing.