Fortran Coder

查看: 12151|回复: 9
打印 上一主题 下一主题

[数学库] MKL的各类子程序重定位问题

[复制链接]

18

帖子

3

主题

0

精华

熟手

F 币
116 元
贡献
73 点
跳转到指定楼层
楼主
发表于 2014-6-30 15:04:56 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 山大克鲁士 于 2014-6-30 15:13 编辑

问题描述:在调用MKL的时候,直接拉dll、lib和h,但在实际调用的时候发现,h中声明的函数和dll出口的子程序名字完全对不上。
相关资料:mkl_blas.h、mkl_intel_c_dll.lib、mkl_core.dll
In mkl_blas.h
[Fortran] 纯文本查看 复制代码
void DGEMM(const char *transa, const char *transb, const MKL_INT *m, const MKL_INT *n, const MKL_INT *k,
           const double *alpha, const double *a, const MKL_INT *lda, const double *b, const MKL_INT *ldb,
           const double *beta, double *c, const MKL_INT *ldc);


Dumpbin /exports from mkl_core.dll:
[Fortran] 纯文本查看 复制代码
ordinal   hint   RVA        name
383       17E    0085F1E0   mkl_blas_dgemm


Dumpbin /all from mkl_intel_c_dll.lib:
[Fortran] 纯文本查看 复制代码
Archive member name at D5992: _dgemm.obj/     
5256C8FB time/date Thu Oct 10 23:34:19 2013
         uid
         gid
  100666 mode
     312 size
correct header end

FILE HEADER VALUES
             14C machine (i386)
               2 number of sections
        5256C8FB time date stamp Thu Oct 10 23:34:19 2013
             1E2 file pointer to symbol table
               C number of symbols
               0 size of optional header
               0 characteristics

SECTION HEADER #1
.drectve name
       0 physical address
       0 virtual address
      2E size of raw data
      64 file pointer to raw data
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
  100A00 flags
         Info
         Remove
         1 byte align

RAW DATA #1
  00000000: 2D 64 65 66 61 75 6C 74 6C 69 62 3A 22 75 75 69  -defaultlib:"uui
  00000010: 64 2E 6C 69 62 22 20 2D 64 65 66 61 75 6C 74 6C  d.lib" -defaultl
  00000020: 69 62 3A 22 75 75 69 64 2E 6C 69 62 22 20        ib:"uuid.lib" 

   Linker Directives
   -----------------
   -defaultlib:"uuid.lib"
   -defaultlib:"uuid.lib"

SECTION HEADER #2
   .text name
       0 physical address
       0 virtual address
     114 size of raw data
      92 file pointer to raw data
     1A6 file pointer to relocation table
       0 file pointer to line numbers
       6 number of relocations
       0 number of line numbers
60300020 flags
         Code
         4 byte align
         Execute Read

RAW DATA #2
  00000000: 55 8B EC 83 EC 08 C7 04 24 00 00 00 00 E8 00 00  U.......$.......
  00000010: 00 00 83 C4 04 83 C4 C4 8B 45 08 89 04 24 8B 45  .........E...$.E
  00000020: 0C 89 44 24 04 8B 45 10 89 44 24 08 8B 45 14 89  ..D$..E..D$..E..
  00000030: 44 24 0C 8B 45 18 89 44 24 10 8B 45 1C 89 44 24  D$..E..D$..E..D$
  00000040: 14 8B 45 20 89 44 24 18 8B 45 24 89 44 24 1C 8B  ..E .D$..E$.D$..
  00000050: 45 28 89 44 24 20 8B 45 2C 89 44 24 24 8B 45 30  E(.D$ .E,.D$$.E0
  00000060: 89 44 24 28 8B 45 34 89 44 24 2C 8B 45 38 89 44  .D$(.E4.D$,.E8.D
  00000070: 24 30 8B 45 3C 89 44 24 34 8B 45 40 89 44 24 38  $0.E<.D$4.E@.D$8
  00000080: E8 00 00 00 00 89 45 FC 83 C4 3C 8B 45 FC 85 C0  ......E...<.E...
  00000090: 75 73 83 C4 C4 8B 45 08 89 04 24 8B 45 0C 89 44  us....E...$.E..D
  000000A0: 24 04 8B 45 10 89 44 24 08 8B 45 14 89 44 24 0C  $..E..D$..E..D$.
  000000B0: 8B 45 18 89 44 24 10 8B 45 1C 89 44 24 14 8B 45  .E..D$..E..D$..E
  000000C0: 20 89 44 24 18 8B 45 24 89 44 24 1C 8B 45 28 89   .D$..E$.D$..E(.
  000000D0: 44 24 20 8B 45 2C 89 44 24 24 8B 45 30 89 44 24  D$ .E,.D$$.E0.D$
  000000E0: 28 8B 45 34 89 44 24 2C 8B 45 38 89 44 24 30 8B  (.E4.D$,.E8.D$0.
  000000F0: 45 3C 89 44 24 34 8B 45 40 89 44 24 38 E8 00 00  E<.D$4.E@.D$8...
  00000100: 00 00 83 C4 3C C9 C3 90 E9 00 00 00 00 90 E9 00  ....<...........
  00000110: 00 00 00 90                                      ....

RELOCATIONS #2
                                                Symbol    Symbol
 Offset    Type              Applied To         Index     Name
 --------  ----------------  -----------------  --------  ------
 00000009  DIR32                      00000000         8  _cdecl_xerbla
 0000000E  REL32                      00000000         9  _mkl_serv_set_xerbla_interface
 00000081  REL32                      00000000         A  _mkl_blas_errchk_dgemm
 000000FE  REL32                      00000000         B  _mkl_blas_dgemm
 00000109  REL32                      00000000         3  .text
 0000010F  REL32                      00000000         3  .text

COFF SYMBOL TABLE
000 00000001 ABS    notype       Static       | @feat.00
001 00000000 SECT1  notype       Static       | .drectve
    Section length   2E, #relocs    0, #linenums    0, checksum        0
003 00000000 SECT2  notype       Static       | .text
    Section length  114, #relocs    6, #linenums    0, checksum        0
005 00000000 SECT2  notype ()    External     | _dgemm
006 00000108 SECT2  notype ()    External     | _dgemm_
007 0000010E SECT2  notype ()    External     | _DGEMM
008 00000000 UNDEF  notype ()    External     | _cdecl_xerbla
009 00000000 UNDEF  notype ()    External     | _mkl_serv_set_xerbla_interface
00A 00000000 UNDEF  notype ()    External     | _mkl_blas_errchk_dgemm
00B 00000000 UNDEF  notype ()    External     | _mkl_blas_dgemm

String Table Size = 0x58 bytes


分析讨论:动态库的出口子程序mkl_blas_dgemm,和头文件中声明的函数DGEMM是怎么个对应上的?
分享到:  微信微信
收藏收藏1 点赞点赞 点踩点踩

18

帖子

3

主题

0

精华

熟手

F 币
116 元
贡献
73 点
沙发
 楼主| 发表于 2014-6-30 15:55:01 | 显示全部楼层
本帖最后由 山大克鲁士 于 2014-6-30 15:58 编辑

为啥链接器不会报错呢?例如:unresolved external symbol _DGEMM难道链接器不是根据函数名+参数列表,来确定该函数在dll中的真实地址?

18

帖子

3

主题

0

精华

熟手

F 币
116 元
贡献
73 点
板凳
 楼主| 发表于 2014-7-1 13:32:22 | 显示全部楼层
chuxf 发表于 2014-6-30 16:50
这主要是出于多函数库使用时,避免名称冲突。

比如,某个函数库里有 OpenFile,另一个函数库里也有这个 ...

现在的问题是,他dll的出口函数中只有mkl_blas_dgemm,但是头文件中确是DGEMM,而且没有出现任何与函数名变更相关的宏,比如#define DGEMM mkl_blas_dgemm,但链接器竟然不会报错,神奇了。。。

18

帖子

3

主题

0

精华

熟手

F 币
116 元
贡献
73 点
地板
 楼主| 发表于 2014-7-2 22:42:07 | 显示全部楼层
chuxf 发表于 2014-7-1 14:22
因为有导入库啊。lib里有代码表明 DGEMM 对应什么DLL的导出函数。

导入库我dumpbin在帖子的图里面了,大神能指点下是哪一段吗?
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-3 07:39

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表