新增]外部C"作为一个符号编译器选项? [英] add "extern C" as a compiler option for a symbol?
问题描述
我和FIPS有能力OpenSSL的工作。源$ C $ c为隔离的,不能改变。
要链接到OpenSSL库的静态版本,我们需要做的是:
出口FIPS_SIG =`发现在/ usr /本地/ SSL -iname incore`
出口CC =`发现在/ usr /本地/ SSL -iname fipsld`
出口FIPSLS_CC =`找到的/ usr / bin中-iname gcc`
然后,只需执行:
$ CC $ CFLAGS<来源和GT; -o myprogram<的OpenSSL库>
对于回转的原因是OpenSSL的将插入一个额外的源文件 - fips_ premain.c
- 以及与节目源编译。 (会出现一些额外的步骤,但汇编 fips_ premain.c
是相关步骤)。
然而,当使用 G ++
,一对夫妇的符号是不确定的,因为他们同当安装OpenSSL的C编译器编译,当如上调用G ++找不到他们
/tmp/fips_$p$pmain-20db15.o:在功能`FINGERPRINT_ $ P $段Pmain():
/usr/local/ssl/fips-2.0/lib/fips_$p$pmain.c:103:未定义参考`FIPS_text_start()
/usr/local/ssl/fips-2.0/lib/fips_$p$pmain.c:116:未定义参考`FIPS_incore_fingerprint(无符号字符*,无符号整型)
如果我添加了 - 不还原函数
链接选项,这里是输出:
/tmp/fips_$p$pmain-be4611.o:在功能`_Z19FINGERPRINT_ premainv:
/usr/local/ssl/fips-2.0/lib/fips_$p$pmain.c:103:未定义参考`_Z15FIPS_text_startv
/usr/local/ssl/fips-2.0/lib/fips_$p$pmain.c:116:未定义参考`_Z23FIPS_incore_fingerprintPhj
下面感兴趣的行 fips_ premain.c
(约85行):
的extern常量无效* FIPS_text_start(),* FIPS_text_end();
的extern const的无符号字符FIPS_rodata_start [],FIPS_rodata_end [];
的extern unsigned char型FIPS_signature [20];
的extern unsigned int类型FIPS_incore_fingerprint(无符号字符*,无符号整型);
有没有一种方法来标记符号为的externC
命令行?
与 G ++
直供 -xc
开关编译命令行上的文件之前,会迫使它被编译为C文件,而不是默认的C ++。
从 Fipsld和C ++ 页:
打开fipsld ++并找到fips_ premain.c编译发生。它是通过变量{preMAIN_C}编译...结果
结果
更改行,以便-xçpreceeds$ {preMAIN_C},而-x没有跟随它。
块引用>$ {CC} $ {CANISTER_O_CMD:+$ {} CANISTER_O_CMD} \\
-x C$ {preMAIN_C}-x无\\
$ {_ WL_ $ P $}段Pmain$ @
在fips_ premain.c强制C语言编译适用于所有配置(库,共享对象和可执行文件),所以你是安全的将其应用到fipsld ++的所有部分。
块引用>I'm working with FIPS Capable OpenSSL. The source code is sequestered and cannot be changed.
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`
Then, simply perform:
$CC $CFLAGS <sources> -o myprogram <openssl libs>
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 offips_premain.c
is the relevant step).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)'
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'
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);
Is there a way to mark a symbol as
extern "C"
from the command line?解决方案Supplying the
-x c
switch withg++
before the file on the compilation command line will force it to be compiled as a C file instead of the default C++.From the Fipsld and C++ page:
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} "$@"
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++.
这篇关于新增]外部C&QUOT;作为一个符号编译器选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!