<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://jogamp.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.2"
          urlbase="https://jogamp.org/bugzilla/"
          
          maintainer="sgothel@jausoft.com"
>

    <bug>
          <bug_id>1508</bug_id>
          
          <creation_ts>2024-05-17 12:55:36 +0200</creation_ts>
          <short_desc>Segfault when unpacking .so from JAR</short_desc>
          <delta_ts>2024-05-17 12:55:36 +0200</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>3</classification_id>
          <classification>JogAmp</classification>
          <product>Gluegen</product>
          <component>core</component>
          <version>2.5.0</version>
          <rep_platform>All</rep_platform>
          <op_sys>linux</op_sys>
          <bug_status>UNCONFIRMED</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P4</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="Owen Riddy">owen.riddy</reporter>
          <assigned_to name="Sven Gothel">sgothel</assigned_to>
          
          
          <cf_type>DEFECT</cf_type>
          <cf_scm_refs></cf_scm_refs>
          <cf_workaround>---</cf_workaround>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>7173</commentid>
    <comment_count>0</comment_count>
    <who name="Owen Riddy">owen.riddy</who>
    <bug_when>2024-05-17 12:55:36 +0200</bug_when>
    <thetext>Hey! 

JOGL is crashing the JVM if an standalone jar is used with the shared libraries stored in some.jar!/natives/linux-amd64/lib*.so. I posted on the about a month ago with an initial assessment of the failure https://forum.jogamp.org/Segfault-loading-native-libraries-td4043450.html. Then I went on holiday and my graphics card died so it took a little longer to get back than I had hoped. I now believe this is a duplicate of #1046 - but I don&apos;t have access to the .jar used in 1046 (and I have done hours of investigating to try and figure out what is happening) so I hope I will be forgiven for raising a new bug. I don&apos;t really understand the linux dynamic linker ld.so, so there is also a bit of speculation here, forgive inaccuracies:

1) All the .so detection code is working fine. The .so are fine. Gluegen&apos;s loading logic is also fine. The crash is deterministic but hard to debug because a lot of it is happening outside Java. Bug appears in 2.3.2, 2.5.0 and a random master branch (commit hash d9604cf4687 from ~3 months ago).

2) When ld.so loads a dynamic library it can handle pointers in 2 ways - either it loads the library into memory and patches all the pointers in RAM or it can store a &quot;start of library&quot; address and use the pointers as offsets. It works out which mode it is operating in by whether the memory is writable-only (assumes first method) or not (assumes second). I think this crash is because libgluegen_rt.so enters a state where the library is set up the second way, but the memory is writeable and glibc gets befuddled. The evidence for this was gathered by analysing a crash log with `coredumpctl` and `coredumpctl debug`. 

3) I believe the trigger in Gluegen (evidence: lots of printline debugging, thinking hard and `strace`) is that we copy libgluegen.so to disk, System.load() it, then truncate it and re-write it a little later. Possibly this is an interaction with mmap? I dunno.

4) I believe this bug can be fixed by adjusting com/jogamp/common/util/JarUtil.java so that extract doesn&apos;t overwrite existing files. I added this a little bit before the OutputStream was created (around line 628) and the crash went away:

...
else if (destFile.exists()) {
  System.out.println(&quot;Crash be gone!&quot;);
}
...

5) Bug #1046 attracted the comment &quot;The provided test jar file does not comply w/ our supported models .. (separate, fat, &apos;tagged&apos;).&quot;. I believe that but I don&apos;t understand why - I thought this layout was a so-called &quot;fat jar&quot;. In this case, I would beg politely that the file truncate stops since it&apos;d make the obvious way work for Clojure devs.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>