Skip to content

M2 Pro, arm64 system architecture got Linking failed with exit code: 1 #428

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

Open
sandeep2244 opened this issue May 15, 2023 · 7 comments
Open

Comments

@sandeep2244
Copy link

sandeep2244 commented May 15, 2023

Error log

3 warnings generated.
ld: can't link with a main executable file '/opt/homebrew/Cellar/postgresql@14/14.8/bin/postgres' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for PostgreSQL PL/Java 1.6.4:
[INFO] 
[INFO] PostgreSQL PL/Java ................................. SUCCESS [  3.587 s]
[INFO] PL/Java API ........................................ SUCCESS [ 10.301 s]
[INFO] PL/Java backend Java code .......................... SUCCESS [  9.538 s]
[INFO] PL/Java PGXS ....................................... SUCCESS [  5.890 s]
[INFO] PL/Java backend native code ........................ FAILURE [  7.588 s]
[INFO] PL/Java Ant tasks .................................. SKIPPED
[INFO] PL/Java examples ................................... SKIPPED
[INFO] PL/Java packaging .................................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE

[ERROR] Failed to execute goal org.postgresql:pljava-pgxs:1.6.4:scripted-goal (build-shared-object) on project pljava-so: Linking failed with exit code: 1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.postgresql:pljava-pgxs:1.6.4:scripted-goal (build-shared-object) on project pljava-so: Linking failed with exit code: 1

I have arm64 system architecture. It's failing on project pljava-so

Originally posted by @sandeep2244 in #411 (comment)

@jcflack
Copy link
Contributor

jcflack commented May 15, 2023

From the information you have supplied, it is difficult to offer suggestions. Have you looked at the information here

https://tada.github.io/pljava/build/build.html#Troubleshooting_the_build

and on the build tips page it links to?

They will suggest ways of capturing more useful information (and then how to filter that down to the key information most useful to report).

@sandeep2244
Copy link
Author

@jcflack , yes i checked the build info page and troubleshoot page.

log info i can share more here... It seems issue with arm64 architecture.

`

/Users/sandeepgadhiya/Documents/pljava-1_6_4/pljava-so/src/main/c/type/Type.c:1084:26: warning: cast from 'void (*)(PgObject)' (aka 'void (*)(struct PgObject_ *)') to 'DatumCoercer' (aka 'union jvalue (*)(struct Type_ *, unsigned long)') converts to incompatible function type [-Wcast-function-type]
        self->coerceDatum     = (DatumCoercer)_PgObject_pureVirtualCalled;
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/sandeepgadhiya/Documents/pljava-1_6_4/pljava-so/src/main/c/type/Type.c:1085:26: warning: cast from 'void (*)(PgObject)' (aka 'void (*)(struct PgObject_ *)') to 'ObjectCoercer' (aka 'unsigned long (*)(struct Type_ *, struct _jobject *)') converts to incompatible function type [-Wcast-function-type]
        self->coerceObject    = (ObjectCoercer)_PgObject_pureVirtualCalled;
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/sandeepgadhiya/Documents/pljava-1_6_4/pljava-so/src/main/c/type/Type.c:1176:3: warning: cast from 'void (*)(PgObject)' (aka 'void (*)(struct PgObject_ *)') to 'TypeObtainer' (aka 'struct Type_ *(*)(unsigned int)') converts to incompatible function type [-Wcast-function-type]
                (TypeObtainer)_PgObject_pureVirtualCalled);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 warnings generated.
ld: can't link with a main executable file '/opt/homebrew/Cellar/postgresql@14/14.8/bin/postgres' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for PostgreSQL PL/Java 1.6.4:
[INFO] 
[INFO] PostgreSQL PL/Java ................................. SUCCESS [  3.587 s]
[INFO] PL/Java API ........................................ SUCCESS [ 10.301 s]
[INFO] PL/Java backend Java code .......................... SUCCESS [  9.538 s]
[INFO] PL/Java PGXS ....................................... SUCCESS [  5.890 s]
[INFO] PL/Java backend native code ........................ FAILURE [  7.588 s]
[INFO] PL/Java Ant tasks .................................. SKIPPED
[INFO] PL/Java examples ................................... SKIPPED
[INFO] PL/Java packaging .................................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  37.131 s
[INFO] Finished at: 2023-05-15T10:41:48+05:30
[INFO] ------------------------------------------------------------------------
[WARNING] 
[WARNING] Plugin validation issues were detected in 10 plugin(s)
[WARNING] 
[WARNING]  * org.apache.maven.plugins:maven-jar-plugin:3.0.2
[WARNING]  * org.apache.maven.plugins:maven-resources-plugin:3.0.1
[WARNING]  * org.apache.maven.plugins:maven-install-plugin:2.5.2
[WARNING]  * org.apache.maven.plugins:maven-compiler-plugin:3.8.1
[WARNING]  * org.apache.maven.plugins:maven-plugin-plugin:3.6.0
[WARNING]  * org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4
[WARNING]  * org.postgresql:pljava-pgxs:1.6.4
[WARNING]  * org.apache.maven.plugins:maven-site-plugin:3.9.1
[WARNING]  * org.codehaus.mojo:properties-maven-plugin:1.0.0
[WARNING]  * org.apache.maven.plugins:maven-resources-plugin:2.5
[WARNING] 
[WARNING] For more or less details, use 'maven.plugin.validation' property with one of the values (case insensitive): [BRIEF, DEFAULT, VERBOSE]
[WARNING] 
[ERROR] Failed to execute goal org.postgresql:pljava-pgxs:1.6.4:scripted-goal (build-shared-object) on project pljava-so: Linking failed with exit code: 1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.postgresql:pljava-pgxs:1.6.4:scripted-goal (build-shared-object) on project pljava-so: Linking failed with exit code: 1
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:347)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:330)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:76)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:910)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: org.apache.maven.plugin.MojoFailureException: Linking failed with exit code: 1
    at org.postgresql.pljava.pgxs.ScriptingMojo.exceptionWrap (ScriptingMojo.java:177)
    at com.oracle.truffle.polyglot.HostMethodDesc$SingleMethod$MHBase.invokeHandle (HostMethodDesc.java:297)
    at com.oracle.truffle.polyglot.HostMethodDesc$SingleMethod$MHBase$1.executeImpl (HostMethodDesc.java:332)
    at com.oracle.truffle.polyglot.GuestToHostRootNode.execute (GuestToHostRootNode.java:87)
    at com.oracle.truffle.api.impl.DefaultCallTarget.callDirectOrIndirect (DefaultCallTarget.java:85)
    at com.oracle.truffle.api.impl.DefaultCallTarget$1.call (DefaultCallTarget.java:123)
    at com.oracle.truffle.polyglot.GuestToHostRootNode.guestToHostCall (GuestToHostRootNode.java:113)
    at com.oracle.truffle.polyglot.HostMethodDesc$SingleMethod$MHBase.invokeGuestToHost (HostMethodDesc.java:322)
    at com.oracle.truffle.polyglot.HostExecuteNode.doInvoke (HostExecuteNode.java:799)
    at com.oracle.truffle.polyglot.HostExecuteNode.doFixed (HostExecuteNode.java:128)
    at com.oracle.truffle.polyglot.HostExecuteNodeGen.executeAndSpecialize (HostExecuteNodeGen.java:141)
    at com.oracle.truffle.polyglot.HostExecuteNodeGen.execute (HostExecuteNodeGen.java:98)
    at com.oracle.truffle.polyglot.HostObject.invokeMember (HostObject.java:388)
    at com.oracle.truffle.polyglot.HostObjectGen$InteropLibraryExports$Cached.invokeMemberNode_AndSpecialize (HostObjectGen.java:1314)
    at com.oracle.truffle.polyglot.HostObjectGen$InteropLibraryExports$Cached.invokeMember (HostObjectGen.java:1289)
    at com.oracle.truffle.api.interop.InteropLibraryGen$CachedDispatch.invokeMember (InteropLibraryGen.java:4871)
    at com.oracle.truffle.js.nodes.function.JSFunctionCallNode$ForeignInvokeNode.executeCall (JSFunctionCallNode.java:1479)
    at com.oracle.truffle.js.nodes.function.JSFunctionCallNode.executeAndSpecialize (JSFunctionCallNode.java:294)
    at com.oracle.truffle.js.nodes.function.JSFunctionCallNode.executeCall (JSFunctionCallNode.java:240)
    at com.oracle.truffle.js.nodes.function.JSFunctionCallNode$InvokeNode.execute (JSFunctionCallNode.java:722)
    at com.oracle.truffle.js.nodes.access.JSWriteCurrentFrameSlotNodeGen.execute_generic4 (JSWriteCurrentFrameSlotNodeGen.java:177)
    at com.oracle.truffle.js.nodes.access.JSWriteCurrentFrameSlotNodeGen.execute (JSWriteCurrentFrameSlotNodeGen.java:93)
    at com.oracle.truffle.js.nodes.access.JSWriteCurrentFrameSlotNodeGen.executeVoid (JSWriteCurrentFrameSlotNodeGen.java:343)
    at com.oracle.truffle.js.nodes.control.ReturnNode$FrameReturnNode.executeVoid (ReturnNode.java:152)
    at com.oracle.truffle.js.nodes.control.IfNode.executeVoid (IfNode.java:181)
    at com.oracle.truffle.js.nodes.control.AbstractBlockNode.executeVoid (AbstractBlockNode.java:91)
    at com.oracle.truffle.js.nodes.control.AbstractBlockNode.execute (AbstractBlockNode.java:84)
    at com.oracle.truffle.js.nodes.control.TryCatchNode.execute (TryCatchNode.java:141)
    at com.oracle.truffle.js.nodes.control.ReturnTargetNode$FrameReturnTargetNode.execute (ReturnTargetNode.java:124)
    at com.oracle.truffle.js.nodes.function.FunctionBodyNode.execute (FunctionBodyNode.java:73)
    at com.oracle.truffle.js.nodes.function.FunctionRootNode.executeInRealm (FunctionRootNode.java:147)
    at com.oracle.truffle.js.runtime.JavaScriptRealmBoundaryRootNode.execute (JavaScriptRealmBoundaryRootNode.java:93)
    at com.oracle.truffle.api.impl.DefaultCallTarget.callDirectOrIndirect (DefaultCallTarget.java:85)
    at com.oracle.truffle.api.impl.DefaultDirectCallNode.call (DefaultDirectCallNode.java:59)
    at com.oracle.truffle.js.nodes.function.JSFunctionCallNode$UnboundJSFunctionCacheNode.executeCall (JSFunctionCallNode.java:1266)
    at com.oracle.truffle.js.nodes.function.JSFunctionCallNode.executeAndSpecialize (JSFunctionCallNode.java:294)
    at com.oracle.truffle.js.nodes.function.JSFunctionCallNode.executeCall (JSFunctionCallNode.java:240)
    at com.oracle.truffle.js.nodes.interop.JSInteropInvokeNode.doCached (JSInteropInvokeNode.java:86)
    at com.oracle.truffle.js.nodes.interop.JSInteropInvokeNodeGen.executeAndSpecialize (JSInteropInvokeNodeGen.java:103)
    at com.oracle.truffle.js.nodes.interop.JSInteropInvokeNodeGen.execute (JSInteropInvokeNodeGen.java:61)
    at com.oracle.truffle.js.runtime.builtins.JSClass.invokeMember (JSClass.java:776)
    at com.oracle.truffle.js.runtime.builtins.JSClassGen$InteropLibraryExports$Cached.invokeMemberNode_AndSpecialize (JSClassGen.java:898)
    at com.oracle.truffle.js.runtime.builtins.JSClassGen$InteropLibraryExports$Cached.invokeMember (JSClassGen.java:874)
    at com.oracle.truffle.polyglot.ProxyInvokeNode.invokeOrExecute (HostInteropReflect.java:608)
    at com.oracle.truffle.polyglot.ProxyInvokeNode.doCachedMethod (HostInteropReflect.java:592)
    at com.oracle.truffle.polyglot.ProxyInvokeNodeGen.executeAndSpecialize (ProxyInvokeNodeGen.java:116)
    at com.oracle.truffle.polyglot.ProxyInvokeNodeGen.execute (ProxyInvokeNodeGen.java:64)
    at com.oracle.truffle.polyglot.ObjectProxyNode.executeImpl (HostInteropReflect.java:535)
    at com.oracle.truffle.polyglot.HostToGuestRootNode.execute (HostToGuestRootNode.java:99)
    at com.oracle.truffle.api.impl.DefaultCallTarget.call (DefaultCallTarget.java:102)
    at com.oracle.truffle.polyglot.ObjectProxyHandler.invoke (HostInteropReflect.java:678)
    at jdk.proxy6.$Proxy49.execute (Unknown Source)
    at org.postgresql.pljava.pgxs.ScriptingMojo.execute (ScriptingMojo.java:84)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:342)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:330)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:76)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:910)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :pljava-so

@jcflack
Copy link
Contributor

jcflack commented May 16, 2023

It looks to me as if it may have been a slightly-dubious shortcut taken 19 years ago, that a modern compiler is taking issue with.

The case for the shortcut may have been that the function does nothing but ereport(ERROR, ...), thereby doing a longjmp, and that it wouldn't matter whether the stack has the expected depth.

But honestly, with only three uses and all in one source file, I don't think it would hurt to have six more lines of code 19 years later, and specialize the function, and eliminate the need to make assumptions about it.

@sandeep2244
Copy link
Author

May i know, Is any plan to merge those fixes ?

@jcflack
Copy link
Contributor

jcflack commented Jun 7, 2023

I wonder whether those three warnings are a red herring here. I also see them in the CI testing here, but only as warnings and they do not fail the build. Also, they are compiler warnings, and your failure seems to be from the linker.

Your linker message is saying "can't link with a main executable file ... for architecture x86_64". You've mentioned you're on arm64?

Is it possible the build script is finding an x86_64 binary of postgres on your system, and trying to link against that?

I'm not sure why there would be an x86_64 binary of postgres on your system, but that seems to be what the linker is complaining about.

@jcflack
Copy link
Contributor

jcflack commented Jun 14, 2023

This issue, along with #411, seems to relate to the Mac OS compiler and linker ending up with some objects built for x86_64 architecture but a postgres binary for arm64, or the other way around.

This may be a matter of not getting the right options to the compiler or linker during the build.

In pljava-so/pom.xml, there is a var configuration = [ section that currently supplies compiling and linking rules for: Linux, Mac OS X, Windows MinGW, and Windows MSVC.

It may be that the "Mac OS X" configuration needs to be either adjusted to use the right command options on both x86_64 and arm64 architecture, or split into two configurations with more specific probe functions so the right configuration is selected.

I do not have ready access to an arm64 Mac to work on that myself, and the architecture does not appear to be available in the GitHub Actions CI environment we are using. I would certainly welcome a pull request if the right options can be figured out.

jcflack added a commit that referenced this issue Feb 20, 2025
None of this is related at all to JEP 472, but some is needed to catch
up with changes on the GitHub runners as the CI would otherwise fail.

The macos-12 runner is gone, and it was the last macos one that supplied
PostgreSQL preinstalled. So rename the workflow from ci-runnerpg to
ci-lazypg ... it still uses the preinstalled PG on runners that have
one, but now resorts to brew to install it on macos.

The macos-13 runner is still Intel-based (and needs PG installed).
The macos-14 runner is ARM64-based (and needs PG installed).

The runners have some Java versions preinstalled, so check for those and
only fetch a JDK if the matrix.java version isn't one of the
preinstalled ones.

Preinstalled versions can be found by their JAVA_HOME_$VERSION_$ARCH
environment variables, except that when $ARCH is ARM64 the environment
variable has arm in lowercase. So much for consistency.

There are newer versions of the setup-java and checkout actions.
The old ones elicited warnings about a deprecated Node.js version.

The old setup-java, when running on macos ARM64 (or arm64), would
happily install an x86_64 JDK. Which would seem to work fine, apparently
running in a compatibility mode, apparently inherited by the C compiler
and linker spawned from Maven. The linker would then report baffling
errors about not finding symbols in PostgreSQL for x86_64! This is the
exact sort of mystery seen and not yet solved in issues #411 and #428.
So, running Maven on a JDK that's for the wrong architecture is now a
known way to cause such a problem, and worth checking in such a case.

Added some ::group:: / ::endgroup:: to make the log output more easily
perused.
@jcflack
Copy link
Contributor

jcflack commented Feb 20, 2025

Recent CI runs (see, for example, c5f9ae4) include the GitHub Actions macos-14 runner, which is arm64-based, and those runs are succeeding.

However, while updating the CI scripts, I did encounter a similarly puzzling linker error that listed a lot of PostgreSQL internal symbols and said it could not find them for x86_64—and this while running on an arm64 platform.

The cause in my case turned out to be that the GitHub Actions setup-java@v1 action had installed a JDK built for x86_64. And it worked, apparently in a compatibility mode. And the compatibility mode was probably inherited by the linker spawned as a subprocess from Maven, so the linker in some way thought it should look for x86_64 symbols.

The solution was to make sure that the JDK being used was built for arm64 (in this case, by upgrading the setup-java action to a newer version smart enough to download a JDK built for the right architecture).

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

No branches or pull requests

2 participants