如何为OpenSSL提供自定义编译器/链接器标志?

DNS*_*DNS 18 linux gcc openssl build

我正在尝试使用-Wa构建OpenSSL, - noexecstack,但在其config命令行中找不到任何地方来提供此标志.我试图设置CFLAGS,但似乎忽略了它,只是使用它自己的.

这是一个自动构建工作,干掉OpenSSL源的干净副本,因此配置脚本的一次性破解实际上不是一个选项.

有没有办法将自定义标志传递给OpenSSL的构建过程?

fre*_*ass 21

后来参加聚会,但这似乎是这样做的正确方法.

config脚本帮助:

$ ./config -h
Usage: config [options]
 -d Add a debug- prefix to machine choice.
 -t Test mode, do not run the Configure perl script.
 -h This help.

Any other text will be passed to the Configure perl script.
See INSTALL for instructions.
Run Code Online (Sandbox Code Playgroud)

因此config脚本将"意外"选项转发给Configure脚本.好吧,让我们看一下Configure脚本对此的看法:

$ ./Configure --help
Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [experimental-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-dso] [no-krb5] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--with-xxx[=vvv]] [--test-sanity] os/compiler[:flags]
Run Code Online (Sandbox Code Playgroud)

[:flags]那条长线末尾的部分?文件中还有一条评论:

# -<xxx> +<xxx> compiler options are passed through
Run Code Online (Sandbox Code Playgroud)

它不是那么明显,因为它不遵循众所周知的标准,但答案是:只需将选项附加到config命令行的末尾即可.

自你发布问题以来已经过了很长时间,我必须补充:

  • 它可能不适用于您正在使用的OpenSSL版本(我的是OpenSSL 1.0);
  • 我觉得有必要发布这个答案,因为之前的答案都没有解决我的问题,我花了一点时间才弄明白这个解决方案.

  • 结果证明这没用.大多数时候你需要设置cflags; 这只是追加他们.没有帮助摆脱已经存在的坏事. (2认同)

ind*_*div 13

config脚本忽略CFLAGS,但不是CC.因此,您可以指定编译器并同时为其指定标志:

export CC="gcc -Wall -DHELLO_WORLD"; ./config
Run Code Online (Sandbox Code Playgroud)

或者,由于config自动检测到您的平台,然后Configure使用预设的编译器设置运行,您可以将编译器标志添加到您的平台配置中.例如,对于我的mac,我在第一次运行时看到这一行config:

Operating system: i386-apple-darwinDarwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386
Configuring for darwin-i386-cc
Run Code Online (Sandbox Code Playgroud)

因此,如果我打开Configure,我可以搜索darwin-i386-cc并添加标志到预设.

如果您没有使用预设配置,那么您只需将标志直接传递到Configure命令行,它就会使用它们.


Ant*_*ani 5

迟到了,但另一种方法是对生成的 makefile 进行自动编辑。例如,要添加-DPURIFY到标志,我首先进行常规配置,然后:

perl -i~ -plwe 's!^(CFLAG=.*$)!$1 -DPURIFY!' Makefile
Run Code Online (Sandbox Code Playgroud)

不是最优雅的解决方案,但它对我有用。