OpenBSD 5.9 无法预加载库 ''

OpenBSD 5.9 无法预加载库 ''

我针对 Linux 和 OpenBSD 进行开发,有时会收到错误消息can't preload library- 你知道这意味着什么吗?

我得到的确切输出是:

: can't preload library

当我尝试运行脚本和/或二进制文件时。这似乎与引用有关,但我不确定。

这个问题在Linux上不会出现,只在OpenBSD上出现。

在此输入图像描述

代码是这里但我不知道它的作用:

void
_dl_dopreload(char *paths)
{
    char        *cp, *dp;
    elf_object_t    *shlib;

    dp = paths = _dl_strdup(paths);
    if (dp == NULL) {
        _dl_printf("preload: out of memory");
        _dl_exit(1);
    }

    while ((cp = _dl_strsep(&dp, ":")) != NULL) {
        shlib = _dl_load_shlib(cp, _dl_objects, OBJTYPE_LIB,
        _dl_objects->obj_flags);
        if (shlib == NULL) {
            _dl_printf("%s: can't preload library '%s'\n",
                __progname, cp);
            _dl_exit(4);
        }
        _dl_add_object(shlib);
        _dl_link_child(shlib, _dl_objects);
    }
    _dl_free(paths);
    return;
}

这是我的脚本,适用于dashLinux,我尝试使用 OpenBSD:s Korn shell 运行它。

#!/bin/sh
echo "-- Testing our implementation of OpenShell --"
echo ""
echo "- If you have any problem in passing a test read the corresponding"
echo "- source file to understand what the test is checking"
echo ""
printf "********************* PRESS ENTER TO RUN TESTS  ... "
read _

# Key pressed, do something
printf "********************* TEST WILDCARDS \n***** Press any key to listing all files in current directory...\nYou should see filesnames *.* below "
read _
valgrind --leak-check=full -v ./shell << EOF
ls -al *.*
EOF
printf "********************* TEST ALGORITHMS ...  \n***** Press any key to run the algorithms... .\nYou should see the output from top -b -n1|head -8|tail -1 "
read _
top -b -n1|head -8|tail -1|sort -n|wc -l
valgrind --leak-check=full -v ./shell << EOF
ls|grep open
EOF

printf "********************* TEST ALGORITHMS Part II.  ... .\nYou should see the output from who|awk '{print \$4 ; print \$3}'|sort -n|wc -l. "
read _
valgrind --leak-check=full ./shell << EOF
who|awk '{print \$4 ; print \$3}'|sort -n|wc -l
EOF

printf "********************* TEST CHECKENV.  ..... .\nYou should see the output checkenv below "
read _
valgrind ./shell << EOF
checkenv
EOF
printf "********************* TEST DONE. YOU SHOULD SEE OUTPUT FROM TEST ABOVE ... "
read _

答案1

openbsd在安全性方面有独特的内存管理概念。所以,静态链接无法预加载库。

代码如下:

        shlib = _dl_load_shlib(cp, _dl_objects, OBJTYPE_LIB,
        _dl_objects->obj_flags);
        if (shlib == NULL) {
            _dl_printf("%s: can't preload library '%s'\n",
                __progname, cp);
            _dl_exit(4);
        }

因此,不应将 的值shlib测试为NULL

请尝试加载动态链接相反,图书馆应该可以工作。

相关内容