'\" te .\" Copyright (c) 2008, 2014, Oracle and/or its affiliates.All rights reserved. .TH elfwrap 1 "2014 年 4 月 23 日" "SunOS 5.11" "用户命令" .SH 名称 elfwrap \- 将数据包装在 \fBELF\fR 文件中 .SH 用法概要 .LP .nf \fBelfwrap\fR [\fB-64\fR] [\fB-e\fR \fIend-symbol\fR] [\fB-n\fR \fIsection-name\fR] [\fB-o\fR \fIrelobj-file\fR] [\fB-s\fR \fIstart-symbol\fR] [\fB-z\fR target=\fBsparc\fR | \fBx86\fR] \fIdata-file\fR ... .fi .SH 描述 .sp .LP \fBelfwrap\fR 实用程序可利用一个或多个数据文件创建 \fBELF\fR 可重定位目标文件。可重定位目标文件将每个数据文件封装在单个节中,且其中带有可用于引用该节的符号。可重定位目标文件适合于通过后续链接编辑来包含在程序中。用户可使用关联的符号引用所封装的数据。 .sp .LP 缺省情况下,将创建 32 位 \fBELF\fR 可重定位目标文件,这适用于在其上执行 \fBelfwrap\fR 的计算机。\fB-64\fR 选项可用于创建 64 位 \fBELF\fR 可重定位目标文件。\fB-z target\fR 选项可用于针对特定机器类型创建可重定位目标文件。 .sp .LP 缺省情况下,创建的可重定位目标文件为 \fBa.wrap.o\fR。可以使用 \fB-o\fR 选项来指定备用可重定位目标文件名称。 .sp .LP 缺省情况下,\fBbasename\fR(1) 实用程序定义的每个数据文件的基名用于创建分配给关联数据的节和符号名称。可使用 \fB-e\fR、\fB-n\fR 和 \fB-s\fR 选项覆盖这些缺省值。如果没有这些选项,输入数据文件 \fBISV/isv-data\fR 将具有与输出可重定位目标文件内数据关联的以下 \fBELF\fR 信息。 .sp .ne 2 .mk .na \fB名为 \fB\&.isv-data\fR 的 \fBELF\fR 节\fR .ad .sp .6 .RS 4n 该节包含输入数据文件的所有内容。还使用 \fBSHF_SUNW_ELFWRAP\fR 节标志标识节。 .RE .sp .ne 2 .mk .na \fB名为 \fBisv-data_start\fR 的 \fBELF\fR 符号\fR .ad .sp .6 .RS 4n 该符号反映 \fB\&.isv-data\fR 节的起始地址。 .RE .sp .ne 2 .mk .na \fB名为 \fBisv-data_end\fR 的 \fBELF\fR 符号\fR .ad .sp .6 .RS 4n 该符号反映 \fB\&.isv-data\fR 节之后第一个位置的地址。 .RE .SH 选项 .sp .LP 支持以下选项: .sp .ne 2 .mk .na \fB\fB-64\fR\fR .ad .sp .6 .RS 4n 创建 64 位 \fBELF\fR 可重定位目标文件。 .RE .sp .ne 2 .mk .na \fB\fB-e\fR \fIend-symbol\fR\fR .ad .sp .6 .RS 4n 指定将与命令行上跟在此选项之后的输入数据文件结尾关联的符号名称。 .RE .sp .ne 2 .mk .na \fB\fB-n\fR \fIsection-name\fR\fR .ad .sp .6 .RS 4n 指定将用于命令行上跟在此选项之后的输入数据文件的节名称。 .RE .sp .ne 2 .mk .na \fB\fB-o\fR \fIrelobj-file\fR\fR .ad .sp .6 .RS 4n 生成名为 \fIrelobj-file\fR 的可重定位目标文件。 .RE .sp .ne 2 .mk .na \fB\fB-s\fR \fIstart-symbol\fR\fR .ad .sp .6 .RS 4n 指定将与命令行上跟在此选项之后的输入数据文件开头关联的符号名称。 .RE .sp .ne 2 .mk .na \fB\fB-z\fR target=\fBsparc\fR | \fBx86\fR\fR .ad .sp .6 .RS 4n 指定输出可重定位目标文件的机器类型。支持的目标有 \fBsparc\fR 和 \fBx86\fR。使用指定目标的 32 位机器类型,除非存在 \fB-64\fR 选项,这种情况下使用相应的 64 位机器类型。缺省情况下,生成的是 32 位可重定位目标文件,适用于在其上执行 \fBelfwrap\fR 的计算机。 .RE .sp .LP \fB-e\fR、\fB-n\fR 和 \fB-s\fR 选项与命令行上跟在这些选项之后的输入数据文件关联。这些选项在任何输入数据文件之前可以重复,以将唯一名称与各数据文件关联。向多个输入数据文件应用同样的 \fB-e\fR 或 \fB-s\fR 选项会导致在要创建的可重定位目标文件内定义多重定义的符号。这可能会导致该目标文件不适于进行额外的链接编辑。以此方式多次使用这些选项将导致 \fBelfedit\fR 中出现警告消息。 .SH 示例 .sp .LP 以下示例将系统文件 \fBpasswd\fR 和系统文件 \fBgroup\fR 封装在可重定位目标文件 \fBpassgroup.o\fR 中。 .sp .in +2 .nf example% \fBelfwrap -o passgroup.o /etc/passwd /etc/group\fR example% \fBelfdump -c -T PROGBITS passgroup.o\fR Section Header[1]: sh_name: .passwd sh_addr: 0 sh_flags: [ SHF_ALLOC SHF_SUNW_ELFWRAP ] sh_size: 0x5a2 sh_type: [ SHT_PROGBITS ] ... Section Header[2]: sh_name: .group sh_addr: 0 sh_flags: [ SHF_ALLOC SHF_SUNW_ELFWRAP ] sh_size: 0x199 sh_type: [ SHT_PROGBITS ] ... example% \fBelfdump -s passgroup.o | egrep "passwd|group"\fR [2] 0 0 SECT LOCL D 0 .passwd [3] 0 0 SECT LOCL D 0 .group [7] 0 0x5a2 OBJT GLOB D 0 .passwd passwd_start [8] 0x5a2 0 OBJT GLOB D 0 .passwd passwd_end [9] 0 0x199 OBJT GLOB D 0 .group group_start [10] 0x199 0 OBJT GLOB D 0 .group group_end example% \fBstrings -N.passwd passgroup.o | head -1\fR root:x:0:0:Super-User:/:/usr/sbin/sh example% \fBstrings -N.group passgroup.o | head -1\fR root::0: .fi .in -2 .sp .sp .LP 可以从以下用户代码引用可重定位目标文件内的口令数据。 .sp .in +2 .nf example% \fBcat main.c\fR #include extern char passwd_start, passwd_end; void main() { char *pstart = &passwd_start, *pend = &passwd_end; char *str, *lstr; for (lstr = str = pstart; str < pend; str++) { if ((*str == '\en') && (str != (pend - 1))) { (void) printf("%.*s", (++str - lstr), lstr); lstr = str; } } } example% \fBcc -o main main.c passgroup.o\fR example% \fB\&./main\fR root:x:0:0:Super-User:/:/usr/sbin/sh \&.... nobody4:x:65534:65534:SunOS 4.x NFS Anonymous Access User:/: .fi .in -2 .sp .sp .LP 以下示例使用相同的输入文件,但将其数据分配给公用节名称,并将唯一符号名称与各数据关联。 .sp .in +2 .nf example% \fBelfwrap -o passgroup.o -n .rodata \e\fR \fB-s P_START -e P_END /etc/passwd \e\fR \fB-s G_START -e G_END /etc/group\fR example% \fBelfdump -c -T PROGBITS passgroup.o\fR Section Header[1]: sh_name: .rodata sh_addr: 0 sh_flags: [ SHF_ALLOC SHF_SUNW_ELFWRAP ] sh_size: 0x5a2 sh_type: [ SHT_PROGBITS ] ... Section Header[2]: sh_name: .rodata sh_addr: 0 sh_flags: [ SHF_ALLOC SHF_SUNW_ELFWRAP ] sh_size: 0x199 sh_type: [ SHT_PROGBITS ] ... example% \fBelfdump -s passgroup.o | fgrep .rodata\fR [2] 0 0 SECT LOCL D 0 .rodata [3] 0 0 SECT LOCL D 0 .rodata [7] 0 0x5a2 OBJT GLOB D 0 .rodata P_START [8] 0x5a2 0 OBJT GLOB D 0 .rodata P_END [9] 0 0x199 OBJT GLOB D 0 .rodata G_START [10] 0x199 0 OBJT GLOB D 0 .rodata G_END .fi .in -2 .sp .SH 文件 .sp .ne 2 .mk .na \fB\fBa.wrap.o\fR\fR .ad .RS 12n .rt 创建的缺省可重定位目标文件。 .RE .SH 属性 .sp .LP 有关下列属性的说明,请参见 \fBattributes\fR(5): .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性developer/base-developer-utilities _ 接口稳定性Committed(已确定) .TE .SH 另请参见 .sp .LP \fBelfdump\fR(1)、\fBld\fR(1)、\fBstrings\fR(1)、\fBelf\fR(3ELF)、\fBattributes\fR(5)、\fBddi_modopen\fR(9F) .sp .LP \fI《Oracle Solaris 11.3 Linkers and Libraries Guide》\fR .SH 附注 .sp .LP 通过 \fBelfwrap\fR 封装的所有数据必须采用适合目标的格式。 .sp .LP 输入文件的名称促使符号名称的创建与输入文件数据相关联。因此,应唯一地命名输入文件来避免创建同名的符号。