带有调试符号的 Openssl 库

Openssl library with debugging symbols

我最近从源代码构建了 openssl-1.0.1l(带有调试符号)。我写了一个 C 程序,它使用 openssl 库函数执行一些基本的加密。当可执行文件为 运行 时,它会连同结果一起向 stdout.

显示一些信息(如下所示)
Ending BN_CTX_start 
(0x9b03300): 008 001 001 001
   : ^^^         ^^^ 
Starting BN_CTX_get
(0x9b03300): 008 001 001 001 
   : ^^^         ^^^ 
Starting BN_CTX_end
(0x9b03300): 008 001 001 001 010 
   : ^^^         ^^^ 
Ending BN_CTX_end
(0x9b03300): 008 001 001 001 
   : ^^^ 
Starting BN_CTX_end
(0x9b03300): 008 001 001 001 
   : ^^^ 
Ending BN_CTX_end
(0x9b03300): 
   : 
BN_CTX_free, stack-size=32, pool-bignums=16
dmaxs: 08 01 01 01 10 00 00 00 00 00 00 00 00 00 00 00

这是什么 'extra' 信息?为什么要输出?有没有办法禁用它?我要求我的可执行文件只执行它打算执行的操作。

这是代码的一部分。这段代码足以引起上面的问题:

#include <openssl/ecdsa.h>
#include <openssl/obj_mac.h>

int main()
{
    EC_KEY *keyPair = EC_KEY_new();
    EC_GROUP *curve = EC_GROUP_new_by_curve_name(NID_sect163k1);
    EC_KEY_set_group(keyPair, curve);
    EC_KEY_generate_key(keyPair);
}

如果您查看 crypto/bn/bn_ctx.c 文件,您可以看到消息是 BN_CTX_DEBUG 预处理器指令的结果。

默认禁用。您使用哪个命令来配置 OpenSSL 构建?如果您只需要调试符号,请尝试 ./config -d

I tried configuring it with the -UBN_CTX_DEBUG flag.

打开 Configure。找到 table 条目:

"debug",    "gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG 
  -DCRYPTO_MDEBUG -DOPENSSL_NO_ASM -ggdb -g2 -Wformat -Wshadow -Wmissing-prototypes 
  -Wmissing-declarations -Werror::(unknown)::-lefence::::",

删除-DBN_CTX_DEBUG。您可能应该将 -g2 更改为 -g3,这样您的符号定义也会被保留。

然后,./Configure debug.


Openssl [1.0.2] library with debugging symbols

我发现最简单的方法是....

首先,make clean && make dclean整理并删除递归 makefile。

其次,打开 Makefile.org 并将 CFLAG= -O 更改为 CFLAG= -Og -g3(或者 CFLAG= -O0 -g3 如果 GCC 支持 -Og).

第三,打开 Configure 并复制一个预先存在的配置目标(如 linux-generic64)。将其重命名为类似 my-config 的名称。删除与 -Ox-gX 相关的所有内容(或者也在那里添加 -Og -g3)。同时删除 -fomit-frame-pointer.

之类的内容

四、根据你的配置制作:

./Configure my-config
make
make install

作为替代方法,选择开发人员的预配置配置之一。例如,Ben Laurie 是一名开发人员,您可以使用 ./Configure debug-ben-no-opt。它使用 -O0 -g3.

构建

还值得注意的是,Configure 中的配置 table 已在 OpenSSL Master 中消失(预期为 1.1.0 及更高版本的内容)。

取而代之的是 Configurations 文件夹。在该文件夹中,您有类似 10-main.conf 的 CONF 文件,其中的条目如下:

%targets = (
    ...
    ##### MacOS X (a.k.a. Darwin) setup
    "darwin-common" => {
        template         => 1,
        cc               => "cc",
        cflags           => "",
        debug_cflags     => "-g -O0",
        release_cflags   => "-O3",
        thread_cflag     => "-D_REENTRANT",
        sys_id           => "MACOSX",
        lflags           => "-Wl,-search_paths_first%",
        bn_ops           => "BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR",
        perlasm_scheme   => "osx32",
        dso_scheme       => "dlfcn",
        shared_target    => "darwin-shared",
        shared_cflag     => "-fPIC -fno-common",
        shared_ldflag    => "-dynamiclib",
        shared_extension => ".$(SHLIB_MAJOR).$(SHLIB_MINOR).dylib",
    },
    ...
    "darwin-i386-cc" => {
        inherit_from     => [ "darwin-common", asm("x86_asm") ],
        cflags           => "-arch i386 -DL_ENDIAN",
        release_cflags   => "-O3 -fomit-frame-pointer",
        bn_ops           => "BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR",
        perlasm_scheme   => "macosx",
        shared_ldflag    => "-arch i386 -dynamiclib",
    },
    "darwin64-x86_64-cc" => {
        inherit_from     => [ "darwin-common", asm("x86_64_asm") ],
        cflags           => "-arch x86_64 -DL_ENDIAN -Wall",
        bn_ops           => "SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL",
        perlasm_scheme   => "macosx",
        shared_ldflag    => "-arch x86_64 -dynamiclib",
    },
);

我实际上也遇到了类似的问题,但是在 1.1.0(master)上使用 Clang 及其消毒剂。这是我的 99-clang-sanitize.conf 尝试做与您正在做的类似的事情(修改 CFLAGS):

%targets = (
    "darwin-sanitize-x86_64" => {
        sys_id           => "MACOSX",
        # inherit_from     => [ asm("x86_64_asm") ],    
        cc               => "clang",
        cflags           => "-g3 -O1 -fPIC -Wall -fsanitize=undefined -fsanitize=address -arch x86_64 -DL_ENDIAN",
        lflags           => "-arch x86_64",
        bn_ops           => "SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL",
        thread_cflag     => "-D_REENTRANT",
        # perlasm_scheme   => "osx64",
        dso_scheme       => "dlfcn",
        # engines_obj     => "e_padlock-x86_64.o"       
    },
    "darwin-sanitize-i386" => {
        sys_id           => "MACOSX",
        # inherit_from     => [ asm("x86_asm") ],   
        cc               => "clang",
        cflags           => "-g3 -O1 -fPIC -Wall -fsanitize=undefined -fsanitize=address -arch i386 -DL_ENDIAN",
        lflags           => "-arch i386",
        bn_ops           => "BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR",
        thread_cflag     => "-D_REENTRANT",
        # perlasm_scheme   => "osx32",
        dso_scheme       => "dlfcn",
        # engines_obj     => "e_padlock-x86.o"
    },
);

这些是我使用调试符号安装 openssl-1.0.1l 时所遵循的确切步骤,没有额外信息:

  1. 当我 运行 config -d 命令时,输出的最后一行显示 Configured for debug-linux-elf。在 Configure 文件中,我通过删除 -DBN_CTX_DEBUG 更改了 debug-linux-elf 的 table 条目。
  2. 我没有更改那个特定 table 条目中的 -g 标志。
  3. 运行 如下:
    ./config -d
    make
    make test
    sudo make install

问题似乎已解决。感谢@jww 的回答。