gpt4 book ai didi

ubuntu - GnuCOBOL 无法找到动态符号,仅在最近的 Ubuntu 上

转载 作者:太空宇宙 更新时间:2023-11-03 16:44:40 27 4
gpt4 key购买 nike

我认为最近发生了一些变化。

GnuCOBOL 依赖于动态链接,在运行时使用 dlsym 查找符号。这个 CALL 运行时支持代码已经在 OpenCOBOL 中使用了大约 7 年。它不再适用于 Ubuntu 14.04,但适用于 Fedora 19/20。

ldd 不再显示任何使用 -l 列出的库

例如作为测试,Ubuntu 14.04.1

下面的COBOL程序

   identification division.
program-id. simple.

procedure division.
call "gtk_init" using
by value 0
by reference null
returning omitted
end-call
goback.
end program simple.


$ cobc -x -v -lgtk-3 simple.cob
preprocessing simple.cob into /tmp/cob710_0.cob
parsing /tmp/cob710_0.cob (simple.cob)
Return status: 0
translating /tmp/cob710_0.cob into /tmp/cob710_0.c (simple.cob)
gcc -pipe -c -I/usr/local/include -Wno-unused -fsigned-char -Wno-pointer-sign -o "/tmp/cob710_0.o" "/tmp/cob710_0.c"
gcc -pipe -Wl,--export-dynamic -o simple /tmp/cob710_0.o -L/usr/local/lib -lcob -lm -lgmp -lncurses -ldb -ldl -l"gtk-3"

二进制文件没有迹象表明 libgtk-3.so 在其中。

./simple
libcob: Cannot find module 'gtk_init'

$ ldd simple
linux-vdso.so.1 => (0x00007fff2c9fe000)
libcob.so.1 => /usr/local/lib/libcob.so.1 (0x00007f2549b06000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2549740000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f2549439000)
libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f25491c5000)
libncurses.so.5 => /lib/x86_64-linux-gnu/libncurses.so.5 (0x00007f2548fa2000)
libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f2548d78000)
libdb-5.3.so => /usr/lib/x86_64-linux-gnu/libdb-5.3.so (0x00007f25489d6000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f25487d2000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2549d56000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f25485b3000)

然后在 Fedora 20 上,相同版本的编译器(构建略有不同,找到 ncursesw 而不是 ncurses - 假设这不是手头问题的一部分)

$ cobc -x -v -lgtk-3 simple.cob
Command line: cobc -x -v -lgtk-3 simple.cob
Preprocessing: simple.cob -> /tmp/cob20658_0.cob
Return status: 0
Parsing: /tmp/cob20658_0.cob (simple.cob)
Return status: 0
Translating: /tmp/cob20658_0.cob -> /tmp/cob20658_0.c (simple.cob)
Executing: gcc -std=gnu99 -c -I/usr/local/include -pipe -Wno-unused
-fsigned-char -Wno-pointer-sign -o "/tmp/cob20658_0.o"
"/tmp/cob20658_0.c"
Return status: 0
Executing: gcc -std=gnu99 -Wl,--export-dynamic -o "simple"
"/tmp/cob20658_0.o" -L/usr/local/lib -lcob -lm -lgmp
-lncursesw -ldb -ldl -l"gtk-3"
Return status: 0

$ ldd simple
linux-vdso.so.1 => (0x00007fffae9cf000)
libcob.so.4 => /usr/local/lib/libcob.so.4 (0x00007f4ff2548000)
libm.so.6 => /lib64/libm.so.6 (0x0000003e5ae00000)
libgmp.so.10 => /lib64/libgmp.so.10 (0x0000003e7a200000)
libncursesw.so.5 => /lib64/libncursesw.so.5 (0x0000003e5d200000)
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x0000003e69800000)
libdb-5.3.so => /lib64/libdb-5.3.so (0x0000003e6ac00000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000003e5b200000)
libgtk-3.so.0 => /lib64/libgtk-3.so.0 (0x0000003e6ba00000)
libc.so.6 => /lib64/libc.so.6 (0x0000003e5aa00000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003e5b600000)
/lib64/ld-linux-x86-64.so.2 (0x0000003e5a600000)
libgdk-3.so.0 => /lib64/libgdk-3.so.0 (0x0000003e6a800000)
libgmodule-2.0.so.0 => /lib64/libgmodule-2.0.so.0 (0x0000003e65600000)
libpangocairo-1.0.so.0 => /lib64/libpangocairo-1.0.so.0 (0x0000003e75200000)
libX11.so.6 => /lib64/libX11.so.6 (0x00007f4ff2206000)
libXi.so.6 => /lib64/libXi.so.6 (0x0000003e62600000)
libXfixes.so.3 => /lib64/libXfixes.so.3 (0x0000003e5fe00000)
libcairo-gobject.so.2 => /lib64/libcairo-gobject.so.2 (0x0000003e6a400000)
libcairo.so.2 => /lib64/libcairo.so.2 (0x0000003e71000000)
libgdk_pixbuf-2.0.so.0 => /lib64/libgdk_pixbuf-2.0.so.0 (0x0000003e6e000000)
libatk-1.0.so.0 => /lib64/libatk-1.0.so.0 (0x0000003e75600000)
libatk-bridge-2.0.so.0 => /lib64/libatk-bridge-2.0.so.0 (0x0000003e6c600000)
libpangoft2-1.0.so.0 => /lib64/libpangoft2-1.0.so.0 (0x0000003e71c00000)
libpango-1.0.so.0 => /lib64/libpango-1.0.so.0 (0x0000003e73600000)
libfontconfig.so.1 => /lib64/libfontconfig.so.1 (0x0000003e61600000)
libgio-2.0.so.0 => /lib64/libgio-2.0.so.0 (0x0000003e66600000)
libgobject-2.0.so.0 => /lib64/libgobject-2.0.so.0 (0x0000003e5fa00000)
libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x0000003e5e600000)
libXinerama.so.1 => /lib64/libXinerama.so.1 (0x0000003e61e00000)
libXrandr.so.2 => /lib64/libXrandr.so.2 (0x0000003e62200000)
libXcursor.so.1 => /lib64/libXcursor.so.1 (0x0000003e62e00000)
libXcomposite.so.1 => /lib64/libXcomposite.so.1 (0x0000003e74e00000)
libXdamage.so.1 => /lib64/libXdamage.so.1 (0x0000003e67e00000)
libwayland-client.so.0 => /lib64/libwayland-client.so.0 (0x0000003e6ec00000)
libxkbcommon.so.0 => /lib64/libxkbcommon.so.0 (0x0000003e6b000000)
libwayland-cursor.so.0 => /lib64/libwayland-cursor.so.0 (0x0000003e69c00000)
libXext.so.6 => /lib64/libXext.so.6 (0x0000003e5ea00000)
librt.so.1 => /lib64/librt.so.1 (0x0000003e5ce00000)
libgthread-2.0.so.0 => /lib64/libgthread-2.0.so.0 (0x0000003e61a00000)
libharfbuzz.so.0 => /lib64/libharfbuzz.so.0 (0x0000003e6f000000)
libfreetype.so.6 => /lib64/libfreetype.so.6 (0x0000003e60e00000)
libxcb.so.1 => /lib64/libxcb.so.1 (0x0000003e5da00000)
libpixman-1.so.0 => /lib64/libpixman-1.so.0 (0x0000003e6f800000)
libEGL.so.1 => /lib64/libEGL.so.1 (0x0000003e73200000)
libpng16.so.16 => /lib64/libpng16.so.16 (0x0000003e5f600000)
libxcb-shm.so.0 => /lib64/libxcb-shm.so.0 (0x0000003e6e800000)
libxcb-render.so.0 => /lib64/libxcb-render.so.0 (0x0000003e70800000)
libXrender.so.1 => /lib64/libXrender.so.1 (0x0000003e61200000)
libz.so.1 => /lib64/libz.so.1 (0x0000003e5ba00000)
libGL.so.1 => /lib64/libGL.so.1 (0x0000003e68200000)
libatspi.so.0 => /lib64/libatspi.so.0 (0x0000003e6c200000)
libdbus-1.so.3 => /lib64/libdbus-1.so.3 (0x0000003e62a00000)
libexpat.so.1 => /lib64/libexpat.so.1 (0x0000003e60a00000)
libffi.so.6 => /lib64/libffi.so.6 (0x0000003e5ee00000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003e5ca00000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x0000003e5e200000)
libgraphite2.so.3 => /lib64/libgraphite2.so.3 (0x0000003e6fc00000)
libXau.so.6 => /lib64/libXau.so.6 (0x0000003e5d600000)
libX11-xcb.so.1 => /lib64/libX11-xcb.so.1 (0x0000003e65e00000)
libxcb-dri2.so.0 => /lib64/libxcb-dri2.so.0 (0x0000003e67200000)
libxcb-xfixes.so.0 => /lib64/libxcb-xfixes.so.0 (0x0000003e70400000)
libxcb-shape.so.0 => /lib64/libxcb-shape.so.0 (0x0000003e72a00000)
libgbm.so.1 => /lib64/libgbm.so.1 (0x0000003e70c00000)
libudev.so.1 => /lib64/libudev.so.1 (0x0000003e63200000)
libwayland-server.so.0 => /lib64/libwayland-server.so.0 (0x0000003e74a00000)
libglapi.so.0 => /lib64/libglapi.so.0 (0x0000003e67600000)
libdrm.so.2 => /lib64/libdrm.so.2 (0x0000003e67a00000)
libxcb-glx.so.0 => /lib64/libxcb-glx.so.0 (0x0000003e66e00000)
libXxf86vm.so.1 => /lib64/libXxf86vm.so.1 (0x0000003e66200000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x0000003e5c600000)
liblzma.so.5 => /lib64/liblzma.so.5 (0x0000003e5c200000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003e5be00000)

Ubuntu 上生成的 C 代码(GnuCOBOL 使用 C 中间体)

/* Line: 4         : CALL               : simple.cob */
cob_procedure_params[0] = (cob_field *)&c_1;
cob_procedure_params[1] = NULL;
cob_glob_ptr->cob_call_params = 2;
if (unlikely(call_gtk_init.funcvoid == NULL)) {
call_gtk_init.funcvoid = cob_resolve_cobol ("gtk_init", 0, 1);
}
call_gtk_init.funcnull ((cob_s32_t)0LL, NULL);
b_1 = 0;

和软呢帽

/* Line: 4         : CALL               : simple.cob */
cob_procedure_params[0] = (cob_field *)&c_1;
cob_procedure_params[1] = NULL;
cob_glob_ptr->cob_call_params = 2;
if (unlikely(call_gtk_init.funcvoid == NULL)) {
call_gtk_init.funcvoid = cob_resolve_cobol ("gtk_init", 0, 1);
}
call_gtk_init.funcnull ((cob_s32_t)0LL, NULL);
b_1 = 0;

当从 C 调用 gtk_init 时,我在 Ubuntu 上得到了很好的结果(完整的 ELF 链接提示),而不是作为传递给 cob_resolve 的字符串。使用 gcc -o simple simple-gtk.c -lgtk-3 测试

那么围绕 -llibname 的假设发生了什么变化?它似乎没有包含在 dlopen 的 ELF 数据中,甚至懒得尝试寻找 libgtk-3.so

更多信息:Ubuntu 上错误的编译行确实让它看起来应该可以正常工作。 (拼写错误的 gtk)

$ cobc -x -v -lgkt-3 simple.cob
Command line: cobc -x -v -lgkt-3 simple.cob
Preprocessing: simple.cob -> /tmp/cob13556_0.cob
Return status: 0
Parsing: /tmp/cob13556_0.cob (simple.cob)
Return status: 0
Translating: /tmp/cob13556_0.cob -> /tmp/cob13556_0.c (simple.cob)
Executing: gcc -std=gnu99 -c -I/usr/local/include -pipe -Wno-unused
-fsigned-char -Wno-pointer-sign -o "/tmp/cob13556_0.o"
"/tmp/cob13556_0.c"
Return status: 0
Executing: gcc -std=gnu99 -Wl,--export-dynamic -o "simple"
"/tmp/cob13556_0.o" -L/usr/local/lib -lcob -lm -lgmp -lncurses
-ldb -ldl -l"gkt-3"
/usr/bin/ld: cannot find -lgkt-3
collect2: error: ld returned 1 exit status
Return status: 256

然而,使用正确的编译行,ELF 没有显示任何指向 gtk-3 的链接提示

我断断续续地为这个问题苦恼了一段时间。寻找关于 Ubuntu 和 gcc 和/或 ld 和/或 dlopen dlsym 更改了哪些假设的提示。

open-cobol 软件包已经在 Debian 和 Ubuntu 存储库中运行了好几年。甚至 Ubuntu 上的旧版本 GnuCOBOL(GNU Cobol 和/或 OpenCOBOL)现在都失败了。事情发生了变化,我们没有收到备忘录。非常愿意更改编译器源代码,但首先要寻找友好的 StackOverflow 见解。

这似乎不是本地环境问题,因为这个 Ubuntu 问题也出现在其他人身上。这也感觉像是那些 DOH 之一!易于解决问题。

非常愿意添加更多编译日志、LD_DEBUG=all dumps 或 straces 等。

最佳答案

这看起来是对 ubuntu 的编译器驱动程序所做的更改 - 它在将代码发送到 collect2 时将 --as-needed 选项添加到编译行又名链接器。

要了解发生了什么,我们需要比显示的更多地分解 cobc 的执行:

cobc -x -v simple.cob -lgtk-3
preprocessing simple.cob into /tmp/cob2743_0.cob
translating /tmp/cob2743_0.cob into /tmp/cob2743_0.c
gcc -pipe -c -Wno-unused -fsigned-char -Wno-pointer-sign -o /tmp/cob2743_0.o /tmp/cob2743_0.c
gcc -pipe -Wl,--export-dynamic -o simple /tmp/cob2743_0.o -L/usr/lib -lcob -lm -lgmp -lncurses -ldb -ldl -lgtk-3

如果我们将其分解为生成 C 代码,然后对其进行编译,我们将得到:

cobc -C -x -v simple.cob
gcc -pipe -c -Wno-unused -fsigned-char -Wno-pointer-sign -o simple.o simple.c
gcc -pipe -Wl,--export-dynamic -o simple simple.o -L/usr/lib -lcob -lm -lgmp -lncurses -ldb -ldl -lgtk-3

我们需要将最后一行 gcc 进一步反汇编成:

gcc -### -pipe -Wl,--export-dynamic -o simple simple.o  -L/usr/lib -lcob -lm -lgmp -lncurses -ldb -ldl -lgtk-3

产生输出:

 /usr/lib/gcc/x86_64-linux-gnu/4.8/collect2 "--sysroot=/" --build-id --eh-frame-hdr -m elf_x86_64 "--hash-style=gnu" --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -z relro -o simple /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.8/crtbegin.o -L/usr/lib -L/usr/lib/gcc/x86_64-linux-gnu/4.8 -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. --export-dynamic simple.o -lcob -lm -lgmp -lncurses -ldb -ldl -lgtk-3 -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o

问题是 first --as-needed 选项的存在 - 它覆盖了命令中所有显式的 -l 选项行 - 如果在构成依赖库的文件的 .o 中找不到任何内容,它不会链接库 - 这就是确切的动态加载情况。

这好像be the case since Oneiric .

这个最简单的解决方法是添加:

COB_LDFLAGS=-Wl,--no-as-needed

您的环境应该可以解决链接问题。

关于ubuntu - GnuCOBOL 无法找到动态符号,仅在最近的 Ubuntu 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26227458/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com