tada / pljava

PL/Java is a free add-on module that brings Java™ Stored Procedures, Triggers, Functions, Aggregates, Operators, Types, etc., to the PostgreSQL™ backend.
http://tada.github.io/pljava/
Other
238 stars 77 forks source link

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

Open sandeep2244 opened 1 year ago

sandeep2244 commented 1 year ago

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 https://github.com/tada/pljava/issues/411#issuecomment-1547349010

jcflack commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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

jcflack commented 1 year ago

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 commented 1 year ago

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.