/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <unistd.h>
#include <fcntl.h>
#include <libgen.h>
#include <errno.h>
#include <libelf.h>
#include <stdio.h>
#include <strings.h>
#include <msg.h>
#include <machdep.h>
#include <_libelf.h>
#include <_elfwrap.h>
/*
* This module is compiled to support 32-bit and 64-bit class objects. Define
* the necessary interfaces for these classes.
*/
#if defined(_ELF64)
#else
#endif
{ NULL, 0, 0 }
};
/*
* Process all input files. These contain the data that will be assigned to a
* new ELF section.
*/
int
{
/*
* Make sure we have access to read each input file, and prepare an
* output section descriptor for each. Note, we assign section indexes
* starting at 1, as section index 0 is special, and is created by
* libelf.
*/
/*
* Close any previously opened file.
*/
if (fd != -1)
/*
* Identify the section.
*/
ret = 1;
continue;
}
ret = 1;
continue;
}
continue;
}
ret = 1;
continue;
}
AL_CNT_WOSECS) == 0) {
return (1);
}
/*
* Each data section contributes:
*
* i. its basename, prefixed with a "dot", to the .shstrtab.
* ii. a section symbol.
* iii. a data symbol, using the basename, with an
* appended "_data" string.
* iv. a data size symbol, using the basename with an
* appended "_size" string.
*/
}
if (fd != -1)
/*
* If an error occurred, or no input files contributed data, bail now.
*/
return (1);
/*
* Create section descriptors for .symtab, .strtab, and .shstrtab.
*/
/*
* Identify the section.
*/
AL_CNT_WOSECS) == 0) {
return (1);
}
/*
* Each standard section contributes:
*
* i. its section name to the .shstrtab.
* ii. a section symbol.
*/
odp->od_symtabno++;
}
/*
* The symbol table requires an initial NULL entry and a following
* FILE entry. Both string tables require an initial NULL byte.
* The .strtab requires room for the output file name (STT_FILE).
*/
odp->od_shstrtabsz++;
return (0);
}
/*
* Having captured all input data, create the output file.
*/
int
{
/*
* Obtain any target specific ELF information.
*/
if (mach == 0)
switch (mach) {
#if !defined(lint)
case EM_SPARC:
break;
case EM_SPARCV9:
break;
case EM_386:
break;
case EM_AMD64:
break;
#else
default:
target_init(&tdesc);
break;
#endif
}
/*
* Create a new ELF descriptor for the new output file.
*/
elf_errmsg(elf_errno()));
return (1);
}
/*
* Create and initialize the new ELF header.
*/
elf_errmsg(elf_errno()));
return (1);
}
/*
* Note, the ELF header is initialized to reflect the host running
* elfwrap(1) rather than the target. Using host byte order allows
* elfwrap(1) to create the object data. Prior to the final update,
* the output ELF header is modified to reflect the target, causing
* libelf to produce the output object using the correct byte order
* and other target information.
*/
/*
* Create the required number of new sections, their associated section
* header, and an initial data buffer.
*/
return (1);
}
return (1);
}
/*
* Assign the section type and flags.
*/
return (1);
}
case SHT_PROGBITS:
/*
* If this is a PROGBITS section, then the data
* originates from an input file. Assign the data
* buffer to this input file and provide a default
* alignment.
*/
break;
case SHT_SYMTAB:
/*
* If this is the symbol table, use the symbol count to
* reserve sufficient space for the symbols we need.
*/
break;
case SHT_STRTAB:
/*
* If this is a string table, use the table size to
* reserve sufficient space for the strings we need.
*/
else
break;
}
}
/*
* Write the ELF data into a memory image.
*/
elf_errmsg(elf_errno()));
return (1);
}
/*
* Assign an ELF descriptor to the memory image.
*/
elf_errmsg(elf_errno()));
return (1);
}
/*
* Get the ELF header from the memory image.
*/
elf_errmsg(elf_errno()));
return (1);
}
/*
* Read the section header and data from the new sections of the
* memory image.
*/
return (1);
}
return (1);
}
return (1);
}
continue;
/*
* Remember the symbol table and string tables, so that they
* can be filled in later.
*/
} else {
}
}
}
/*
* Update the ELF header with the .shstrtab index.
*/
/*
* Set up the string table entries, and skip the first byte.
*/
strtabent++;
shstrtabent++;
/*
* Skip the first symbol table entry. Write a FILE entry, and set
* up for adding sections and data symbols. Associate the symbol
* table with the string table.
*/
secsymtabent++;
secsymtabent++;
/*
* Write the output file name to the .strtab.
*/
/*
* Rescan all the new sections, adding symbols and strings as required.
*/
/*
* Create a section symbol.
*/
secsymtabent++;
/*
* Store the section name, (with an appended "." if the section
* name is derived from the input file name), and point the
* section header to this name.
*/
}
shstrtabent += len;
continue;
/*
* Add a symbol pointing to this PROGBITS section. The value
* is the base offset of this section, which can only be 0.
* The size of the symbol can be taken straight from the section
* header information (that libelf generated).
*/
glbsymtabent++;
/*
* Store this symbol name (with an appended "_data") in the
* string table.
*/
len--;
/*
* Add a symbol indicating the size of this PROGBITS section.
*/
glbsymtabent++;
/*
* Store this symbol name (with an appended "_end") in the
* string table.
*/
}
/*
* Update the .symtab section header with the index of the first
* non-local symbol. The only locals written are the section symbols.
*/
/*
* Having updated the image following the byte order of elfwrap(), seed
* the ELF header with the appropriate target information.
*/
/*
* If the output relocatable object is targeted to a machine with a
* different byte order than the host running elfwrap(1), swap the data
* to the target byte order.
*/
(_elf_swap_wrimage(melf) != 0)) {
elf_errmsg(elf_errno()));
return (1);
}
/*
* Finally, write the updated memory image out to disc.
*/
elf_errmsg(elf_errno()));
return (1);
}
return (0);
}