添加& quot;外部C& quot;作为符号的编译器选项? [英] add "extern C" as a compiler option for a symbol?

查看:118
本文介绍了添加& quot;外部C& quot;作为符号的编译器选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用支持FIPS的OpenSSL.源代码被隔离,无法更改.

I'm working with FIPS Capable OpenSSL. The source code is sequestered and cannot be changed.

要链接到OpenSSL库的静态版本,我们需要做的是:

To link to the static version of the OpenSSL library, all we need to do is:

export FIPS_SIG=`find /usr/local/ssl -iname incore`
export CC=`find /usr/local/ssl -iname fipsld`
export FIPSLS_CC=`find /usr/bin -iname gcc`

然后,只需执行:

$CC $CFLAGS <sources> -o myprogram <openssl libs>

旋转的原因是OpenSSL将插入一个附加的源文件-fips_premain.c-并将其与程序源一起编译. (发生了一些附加步骤,但是相关的步骤是fips_premain.c的编译.)

The reasons for the gyration is OpenSSL will insert an additional source file - fips_premain.c - and compile it with the program sources. (Some additional steps occur, but the compilation of fips_premain.c is the relevant step).

但是,当使用g++时,几个符号是未定义的,因为它们是在安装OpenSSL时由C编译器编译的,而g ++在按上述方式调用时找不到它们:

However, when using g++, a couple of symbols are undefined because they were compiled with the C compiler when OpenSSL was installed, and g++ cannot find them when invoked as above:

/tmp/fips_premain-20db15.o: In function `FINGERPRINT_premain()':
/usr/local/ssl/fips-2.0/lib/fips_premain.c:103: undefined reference to `FIPS_text_start()'
/usr/local/ssl/fips-2.0/lib/fips_premain.c:116: undefined reference to `FIPS_incore_fingerprint(unsigned char*, unsigned int)'

如果添加--no-demangle链接器选项,则输出如下:

If I add the --no-demangle linker option, here's what is output:

/tmp/fips_premain-be4611.o: In function `_Z19FINGERPRINT_premainv':
/usr/local/ssl/fips-2.0/lib/fips_premain.c:103: undefined reference to `_Z15FIPS_text_startv'
/usr/local/ssl/fips-2.0/lib/fips_premain.c:116: undefined reference to `_Z23FIPS_incore_fingerprintPhj'

以下是fips_premain.c中的关注行(第85行附近):

Here are the lines of interest in fips_premain.c (around line 85):

extern const void         *FIPS_text_start(),  *FIPS_text_end();
extern const unsigned char FIPS_rodata_start[], FIPS_rodata_end[];
extern unsigned char       FIPS_signature[20];
extern unsigned int        FIPS_incore_fingerprint(unsigned char *,unsigned int);

是否可以从命令行将符号标记为extern "C"?

Is there a way to mark a symbol as extern "C" from the command line?

推荐答案

在编译命令行上的文件之前,将-x c开关提供给g++会强制将其编译为C文件,而不是默认的C ++.

Supplying the -x c switch with g++ before the file on the compilation command line will force it to be compiled as a C file instead of the default C++.

打开fipsld ++并找到在其中编译fips_premain.c的地方.它是通过变量{PREMAIN_C}编译的.

更改这些行,以使-x c位于"$ {PREMAIN_C}"之前,而-x none位于其后.

Open fipsld++ and find occurrences where fips_premain.c is compiled. It is compiled through the variable {PREMAIN_C} ...

Change the lines so that -x c preceeds "${PREMAIN_C}", and -x none follows it.

${CC}  ${CANISTER_O_CMD:+"${CANISTER_O_CMD}"} \
    -x c "${PREMAIN_C}" -x none \
    ${_WL_PREMAIN} "$@"

在fips_premain.c上强制执行C编译适用于所有配置(库,共享库和可执行文件),因此可以安全地将其应用于fipsld ++的所有部分.

Forcing C compilation on fips_premain.c applies to all configurations (libraries, shared objects, and executables), so you are safe to apply it to all sections of fipsld++.

这篇关于添加&amp; quot;外部C&amp; quot;作为符号的编译器选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆