Go to main content

手册页部分 1:用户命令

退出打印视图

更新时间: 2018年8月8日 星期三
 
 

elfwrap(1)

名称

elfwrap - 将数据包装在ELF文件中

用法概要

elfwrap [-64] [-e end-symbol] [-n section-name] [-o relobj-file]
     [-s start-symbol] [-V] [-z target=sparc | x86] data-file ...

描述

elfwrap 实用程序可利用一个或多个数据文件创建 ELF 可重定位目标文件。可重定位目标文件将每个数据文件封装在单个节中,且其中带有可用于引用该节的符号。可重定位目标文件适合于通过后续链接编辑来包含在程序中。用户可使用关联的符号引用所封装的数据。

缺省情况下,将创建 32 位 ELF 可重定位目标文件,这适用于在其上执行 elfwrap 的计算机。–64 选项可用于创建 64 位 ELF 可重定位目标文件。–z target 选项可用于针对特定机器类型创建可重定位目标文件。

缺省情况下,创建的可重定位目标文件为 a.wrap.o。可以使用 –o 选项来指定备用可重定位目标文件名称。

缺省情况下,basename(1) 实用程序定义的每个数据文件的基名用于创建分配给关联数据的节和符号名称。可使用 –e–n–s 选项覆盖这些缺省值。如果没有这些选项,输入数据文件 ISV/isv-data 将具有与输出可重定位目标文件内数据关联的以下 ELF 信息。

名为 .isv-data 的 ELF 节

该节包含输入数据文件的所有内容。还使用 SHF_SUNW_ELFWRAP 节标志标识节。

名为 isv-data_start 的 ELF 符号

该符号反映 .isv-data 节的起始地址。

名为 isv-data_end 的 ELF 符号

该符号反映 .isv-data 节之后第一个位置的地址。

选项

支持以下选项:

–64

创建 64 位 ELF 可重定位目标文件。

–e end-symbol

指定将与命令行上跟在此选项之后的输入数据文件结尾关联的符号名称。

–n section-name

指定将用于命令行上跟在此选项之后的输入数据文件的节名称。

–o relobj-file

生成名为 relobj-file 的可重定位目标文件。

–s start-symbol

指定将与命令行上跟在此选项之后的输入数据文件开头关联的符号名称。

–z target=sparc | x86

指定输出可重定位目标文件的机器类型。支持的目标有 sparcx86。使用指定目标的 32 位机器类型,除非存在 –64 选项,这种情况下使用相应的 64 位机器类型。缺省情况下,生成的是 32 位可重定位目标文件,适用于在其上执行 elfwrap 的计算机。

–V
–-version

输出版本信息并立即退出。

–?
–-help

输出用法消息并立即退出。

–e–n–s 选项与命令行上跟在这些选项之后的输入数据文件关联。这些选项在任何输入数据文件之前可以重复,以将唯一名称与各数据文件关联。向多个输入数据文件应用同样的 –e–s 选项会导致在要创建的可重定位目标文件内定义多重定义的符号。这可能会导致该目标文件不适于进行额外的链接编辑。以此方式多次使用这些选项将导致 elfwrap 中出现警告消息。

示例

以下示例将系统文件 passwd 和系统文件 group 封装在可重定位目标文件 passgroup.o 中。

example% elfwrap -o passgroup.o /etc/passwd /etc/group
example% elfdump -c -T PROGBITS passgroup.o

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% elfdump -s passgroup.o | egrep "passwd|group"
  [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% strings -N.passwd passgroup.o | head -1
root:x:0:0:Super-User:/:/usr/sbin/sh
example% strings -N.group passgroup.o | head -1
root::0:

可以从以下用户代码引用可重定位目标文件内的口令数据。

example% cat main.c
#include        <stdio.h>

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 == '\n') && (str != (pend - 1)))  {
            (void) printf("%.*s", (++str - lstr), lstr);
            lstr = str;
        }
    }
}
example% cc -o main main.c passgroup.o
example% ./main
root:x:0:0:Super-User:/:/usr/sbin/sh
....
nobody4:x:65534:65534:SunOS 4.x NFS Anonymous Access User:/:

以下示例使用相同的输入文件,但将其数据分配给公用节名称,并将唯一符号名称与各数据关联。

example% elfwrap -o passgroup.o -n .rodata \
    -s P_START -e P_END /etc/passwd \
    -s G_START -e G_END /etc/group
example% elfdump -c -T PROGBITS passgroup.o

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% elfdump -s passgroup.o | fgrep .rodata
  [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

文件

a.wrap.o

创建的缺省可重定位目标文件。

属性

有关下列属性的说明,请参见 attributes(7)

属性类型
属性值
可用性
developer/base-developer-utilities
接口稳定性
Committed(已确定)

另请参见

elfdump(1)ld(1)strings(1)elf(3ELF)attributes(7)ddi_modopen(9F)

Oracle Solaris 11.4 Linkers and Libraries Guide

附注

通过 elfwrap 封装的所有数据必须采用适合目标的格式。

输入文件的名称促使符号名称的创建与输入文件数据相关联。因此,应唯一地命名输入文件来避免创建同名的符号。