Go to main content

man pages section 1: User Commands

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

elfwrap(1)

Name

elfwrap - wrap data in anELFfile

Synopsis

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

Description

The elfwrap utility creates an ELF relocatable object file from one or more data files. The relocatable object encapsulates each data file within an individual section, together with symbols that can be used to reference the section. The relocatable object is appropriate for inclusion with a subsequent link-edit. Users can reference the encapsulated data using the associated symbols.

By default, a 32–bit ELF relocatable object is created that is appropriate for the machine on which elfwrap is executed. The –64 option can be used to create a 64–bit ELF relocatable object. The –z target option can be used to create a relocatable object for a specific machine type.

By default, the relocatable object a.wrap.o is created. The –o option can be used to specify an alternative relocatable object name.

By default, the base name of each data file, as define by the basename(1) utility, is used to create section and symbol names that are assigned to the associated data. The –e, –n, and –s options can be used to override these defaults. Without these options, an input data file ISV/isv-data, has the following ELF information associated to the data within the output relocatable object.

An ELF section named .isv-data

This section contains the entire contents of the input data file. The section is also identified with the SHF_SUNW_ELFWRAP section flag.

An ELF symbol named isv-data_start

This symbol reflects the starting address of the .isv-data section.

An ELF symbol named isv-data_end

This symbol reflects the address of the first location after the .isv-data section.

Options

The following options are supported:

–64

Create a 64–bit ELF relocatable object.

–e end-symbol

Specifies the symbol name to be associated with the end of the input data file that follows this option on the command line.

–n section-name

Specifies the section name to be used for the input data file that follows this option on the command line.

–o relobj-file

Produce a relocatable object that is named relobj-file.

–s start-symbol

Specifies the symbol name to be associated with the start of the input data file that follows this option on the command line.

–z target=sparc | x86

Specifies the machine type for the output relocatable object. Supported targets are sparc and x86. The 32–bit machine type for the specified target is used unless the –64 option is also present, in which case the corresponding 64–bit machine type is used. By default, the relocatable object that is generated is 32–bit for the machine one which elfwrap is executed.

–V
–-version

Print version information and immediately exit.

–?
–-help

Print usage message and immediately exit.

The –e, –n, and –s options are associated to the input data files that follow these options on the command line. These options can be repeated, prior to any input data file, to associate unique names to each data file. Applying the same –e, or –s options to more than one input data file results in multiply defined symbols being defined within the relocatable object being created. This may render the object unsuitable for additional link-editing. Multiple use of these options in this manner results in warning messages from elfwrap.

Examples

The following example encapsulates the system passwd file and the system group file within a relocatable object 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:

The password data within the relocatable object can be referenced from the following user code.

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:/:

The following example uses the same input files, but assigns their data to a common section name, and associates unique symbol names to each data.

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

Files

a.wrap.o

The default relocatable object file created.

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Availability
developer/base-developer-utilities
Interface Stability
Committed

See Also

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

Oracle Solaris 11.4 Linkers and Libraries Guide

Notes

Any data encapsulated with elfwrap must be in a format appropriate for the destination target.

The name of the input file drives the creation of the symbol names to associate with the input file data. Therefore, input files should be uniquely named to avoid the creation of symbols with the same name.