ghidra2dwarf icon indicating copy to clipboard operation
ghidra2dwarf copied to clipboard

Error looking up function 'dwarf_producer_init': /usr/lib/libdwarf.so: undefined symbol: dwarf_producer_init

Open DCNick3 opened this issue 2 years ago • 2 comments

When using with ghidra 10.3.3 on arch linux, I get the following error:

Traceback (most recent call last):
  File "/home/dcnick3/Downloads/ghidra2dwarf/ghidra2dwarf.py", line 507, in <module>
    dwarf_producer_init(
  File "/home/dcnick3/Downloads/ghidra2dwarf/ghidra2dwarf.py", line 111, in wrapper
    r = fun(*(args + (err,)))
	at com.sun.jna.Function.<init>(Function.java:252)
	at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:594)
	at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:570)
	at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:556)
	at com.sun.jna.Library$Handler.invoke(Library.java:243)
	at jdk.proxy3/jdk.proxy3.$Proxy74.dwarf_producer_init(Unknown Source)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
java.lang.UnsatisfiedLinkError: java.lang.UnsatisfiedLinkError: Error looking up function 'dwarf_producer_init': /usr/lib/libdwarf.so: undefined symbol: dwarf_producer_init

This seems to happen because of version mismatch of system libdwarf and the one used by the script + the loader preferring the system libdwarf over the one provided in the script.

I was able to work around the issue by renaming the library to libdwardf_vendor.so and updating the library to call loadLibrary with dwardf_vendor

DCNick3 avatar Oct 05 '23 10:10 DCNick3

@DCNick3 can you explain in detail how you worked around the issue? Where is the call to loadLibrary? Thanks

francesco-scar avatar Mar 22 '24 17:03 francesco-scar

The call is here I believe.

Here's a complete diff I used for my workaround:

diff --git a/lib/fetch_libs_and_build.sh b/lib/fetch_libs_and_build.sh
index d31b5e5..2917ba7 100755
--- a/lib/fetch_libs_and_build.sh
+++ b/lib/fetch_libs_and_build.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 
 [ ! -f src/main/resources/linux-x86-64/libdwarf.so ] && \
-    curl -o src/main/resources/linux-x86-64/libdwarf.so -L --create-dirs https://github.com/cesena/libdwarf-ghidra2dwarf/releases/download/latest/libdwarf.so
+    curl -o src/main/resources/linux-x86-64/libdwarf_vendor.so -L --create-dirs https://github.com/cesena/libdwarf-ghidra2dwarf/releases/download/latest/libdwarf.so
 
 [ ! -f src/main/resources/win32-x86-64/libdwarf.dll ] && \
     curl -o src/main/resources/win32-x86-64/libdwarf.dll -L --create-dirs https://github.com/cesena/libdwarf-ghidra2dwarf/releases/download/latest/libdwarf.dll
diff --git a/lib/pom.xml b/lib/pom.xml
index b376647..a318e27 100644
--- a/lib/pom.xml
+++ b/lib/pom.xml
@@ -10,8 +10,8 @@
 	<packaging>jar</packaging>
 	<properties>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-		<maven.compiler.source>1.7</maven.compiler.source>
-		<maven.compiler.target>1.7</maven.compiler.target>
+		<maven.compiler.source>1.8</maven.compiler.source>
+		<maven.compiler.target>1.8</maven.compiler.target>
 	</properties>
 	<dependencies>
 		<dependency>
diff --git a/lib/src/main/java/libdwarf/LibdwarfLibrary.java b/lib/src/main/java/libdwarf/LibdwarfLibrary.java
index f6eaa90..88372ca 100644
--- a/lib/src/main/java/libdwarf/LibdwarfLibrary.java
+++ b/lib/src/main/java/libdwarf/LibdwarfLibrary.java
@@ -10,7 +10,7 @@ import com.sun.jna.ptr.LongByReference;
 import com.sun.jna.ptr.PointerByReference;
 
 public interface LibdwarfLibrary extends Library {
-	public static final LibdwarfLibrary INSTANCE = (LibdwarfLibrary)Native.loadLibrary(Platform.isWindows() ? "libdwarf" : "dwarf", LibdwarfLibrary.class);
+	public static final LibdwarfLibrary INSTANCE = (LibdwarfLibrary)Native.loadLibrary(Platform.isWindows() ? "libdwarf" : "dwarf_vendor", LibdwarfLibrary.class);
 
 	// functions
 	String dwarf_errmsg(LibdwarfLibrary.Dwarf_Error Dwarf_Error1);

(the change to use of java 1.8 was probably because that's what I have on my system)

Then I re-built the plugin with the fetch_libs_and_build.sh script in the lib subfolder. After this the build plugin will be located at target/libdwarf.jar

DCNick3 avatar Mar 22 '24 18:03 DCNick3