bad reloc address 0x0 when compiling hsdis (Java HotSpot disassembler plugin) on cygwin
Asked Answered
D

2

4

I'm trying to compile the hsdis-amd64.dll library that the JVM needs to disassemble JIT compiled code.

I followed this accepted answer.

I created a folder structure like this:

+
+- hsdis             // unzipped dir hotspot/src/share/tools/hsdis of openjdk zip
+- binutils-2.24     // unzipped binutils-2.24.tar.gz

First I tried to just compile it using:

$ make OS=Linux MINGW=x86_64-w64-mingw32 BINUTILS=../binutils-2.24

but it failed with

/Linux-amd64/opcodes/libopcodes.a build/Linux-amd64/libiberty/libiberty.a
hsdis.c:32:20: fatal error: sysdep.h: No such file or directory
#include <sysdep.h>
                ^
compilation terminated.

So I applied the patch provided in this accepted answer and tried again.

The compilation failed again

In file included from hsdis.c:34:0:
build/Linux-amd64/bfd/bfd.h:35:2: error: #error config.h must be included before this header
#error config.h must be included before this header
^

I followed the proposal of the compiler and added config.h just before the errno.h include.

Then the error is

e -I../binutils-2.24/bfd -Ibuild/Linux-amd64/bfd -DLIBARCH_amd64 -DLIBARCH=\"amd64\" -DLIB_EXT=\".dll\" -O hsdis.c -shared build/Linux-amd64/bfd/libbfd.a build/Linux-amd64/opcodes/libopcodes.a build/Linux-amd64/libiberty/libiberty.a
build/Linux-amd64/bfd/libbfd.a(compress.o):compress.c:(.text+0x15): undefined reference to `compressBound'
build/Linux-amd64/bfd/libbfd.a(compress.o):compress.c:(.text+0x48): undefined reference to `compress'
build/Linux-amd64/bfd/libbfd.a(compress.o):compress.c:(.text+0x28a): undefined reference to `inflateInit_'
build/Linux-amd64/bfd/libbfd.a(compress.o):compress.c:(.text+0x2c7): undefined reference to `inflate'
build/Linux-amd64/bfd/libbfd.a(compress.o):compress.c:(.text+0x2d6): undefined reference to `inflateReset'
build/Linux-amd64/bfd/libbfd.a(compress.o):compress.c:(.text+0x2f1): undefined reference to `inflateEnd'
/usr/lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/ld: build/Linux-amd64/bfd/libbfd.a(compress.o): bad reloc address 0x0 in section `.pdata'
collect2: error: ld returned 1 exit status

I know that it is a linker problem. For me it seems that it is trying to link against a wrong version, but I might be wrong.

Does anyone knows how to solve this problem or can tell me how to compile the hsdis (HotSpot disassembler plugin)?

Disqualification answered 10/1, 2014 at 11:10 Comment(0)
E
2

There is need to add linking against zlib (Be sure that you install package mingw64-x86_64-zlib in cygwin). correct zlib package for x86_64

Then open Makefile in editor, find rule:

$(TARGET): $(SOURCE) $(LIBS) $(LIBRARIES) $(TARGET_DIR)
    $(CC) $(OUTFLAGS) $(CPPFLAGS) $(CFLAGS) $(SOURCE) $(DLDFLAGS) $(LIBRARIES)

Add "-static -lz" to second line to make that:

$(TARGET): $(SOURCE) $(LIBS) $(LIBRARIES) $(TARGET_DIR)
    $(CC) $(OUTFLAGS) $(CPPFLAGS) $(CFLAGS) $(SOURCE) $(DLDFLAGS) $(LIBRARIES) -static -lz
Embassy answered 14/1, 2014 at 9:21 Comment(4)
You need to install package mingw64-x86_64-zlib in cygwin.Embassy
You need to install mingw64-x86_64-zlib (you mismatch it with zlib-devel on your screenshot)Embassy
Check for "ls /usr/x86_64-w64-mingw32/sys-root/mingw/lib/libz.*" in cygwin console. There (if zlib for Win64 toolchain correctly installed) must be two files: libz.a and libz.dll.aEmbassy
Thanks, now it compiles perfectly after I did a make clean.Stator
D
3

The problem could be solved following Marat Buharov's answer.

Nevertheless here are some links where you can find a pre-comiled hsdis plugin:

I tried http://lafo.ssw.uni-linz.ac.at/hsdis/intel/hsdis-amd64.dll with jdk1.7.0_02 and it worked.

Disqualification answered 10/1, 2014 at 18:50 Comment(0)
E
2

There is need to add linking against zlib (Be sure that you install package mingw64-x86_64-zlib in cygwin). correct zlib package for x86_64

Then open Makefile in editor, find rule:

$(TARGET): $(SOURCE) $(LIBS) $(LIBRARIES) $(TARGET_DIR)
    $(CC) $(OUTFLAGS) $(CPPFLAGS) $(CFLAGS) $(SOURCE) $(DLDFLAGS) $(LIBRARIES)

Add "-static -lz" to second line to make that:

$(TARGET): $(SOURCE) $(LIBS) $(LIBRARIES) $(TARGET_DIR)
    $(CC) $(OUTFLAGS) $(CPPFLAGS) $(CFLAGS) $(SOURCE) $(DLDFLAGS) $(LIBRARIES) -static -lz
Embassy answered 14/1, 2014 at 9:21 Comment(4)
You need to install package mingw64-x86_64-zlib in cygwin.Embassy
You need to install mingw64-x86_64-zlib (you mismatch it with zlib-devel on your screenshot)Embassy
Check for "ls /usr/x86_64-w64-mingw32/sys-root/mingw/lib/libz.*" in cygwin console. There (if zlib for Win64 toolchain correctly installed) must be two files: libz.a and libz.dll.aEmbassy
Thanks, now it compiles perfectly after I did a make clean.Stator

© 2022 - 2024 — McMap. All rights reserved.