在cygwin上编译hsdis(Java HotSpot反汇编程序插件)时,错误的reloc地址0x0

我正在尝试编译JVM需要反汇编JIT编译代码的hsdis-amd64.dll库。

我按照这个接受的答案。

  • 我安装了cygwin
  • 下载了openjdk-7u40-fcs-src-b43-26_aug_2013.zip
  • 并下载了binutils-2.24.tar.gz

我创建了一个这样的文件夹结构:

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

首先,我尝试使用以下方法编译它:

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

但它失败了

 /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  ^ compilation terminated. 

所以我应用了此接受答案中提供的补丁并再次尝试。

编译再次失败

 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 ^ 

我遵循了编译器的提议,并在errno.h include之前添加了config.h

然后错误是

 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 

我知道这是一个链接器问题。 对我而言,它似乎试图链接错误的版本,但我可能错了。

有谁知道如何解决这个问题或者可以告诉我如何编译hsdis(HotSpot反汇编程序插件)?

需要添加针对zlib的链接(确保在cygwin中安装包mingw64-x86_64-zlib)。 正确的zlib包为x86_64

然后在编辑器中打开Makefile,找到规则:

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

将“-static -lz”添加到第二行以使其成为:

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

Marat Buharov的回答可以解决这个问题。

不过这里有一些链接,你可以找到一个预先编译的hsdis插件:

我用jdk1.7.0_02尝试了http://lafo.ssw.uni-linz.ac.at/hsdis/intel/hsdis-amd64.dll并且它有效。