update.c revision fdf855a7bee8a77bedd222e0fa01b4207ef14952
/*
* 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 (c) 1988 AT&T
* All Rights Reserved
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Update the new output file image, perform virtual address, offset and
* displacement calculations on the program headers and sections headers,
* and generate any new output section information.
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <debug.h>
#include "msg.h"
#include "_libld.h"
/*
* Comparison routine used by qsort() for sorting of the global yymbol list
* based off of the hashbuckets the symbol will eventually be deposited in.
*/
static int
{
}
/*
* Build and update any output symbol tables. Here we work on all the symbol
* tables at once to reduce the duplication of symbol and string manipulation.
* Symbols and their associated strings are copied from the read-only input
* file images to the output image and their values and index's updated in the
* output image.
*/
static Addr
{
#endif
Addr tlsbssaddr = 0;
int start_set = 0;
/* information */
/*
* Initialize pointers to the symbol table entries and the symbol
* table strings. Skip the first symbol entry and the first string
* table byte. Note that if we are not generating any output symbol
* tables we must still generate and update an internal copies so
* that the relocation phase has the correct information.
*/
if (ofl->ofl_ossymshndx)
}
/*
* Initialize the hash table.
*/
if (ofl->ofl_osdynshndx)
}
/*
* symndx is the symbol index to be used for relocation processing. It
* points to the relevant symtab's (.dynsym or .symtab) symbol ndx.
*/
if (dynsym)
symndx = &dynsym_ndx;
else
symndx = &symtab_ndx;
/*
* If we have version definitions initialize the version symbol index
* table. There is one entry for each symbol which contains the symbols
* version index.
*/
versym[0] = 0;
} else
versym = 0;
/*
* If syminfo section exists be prepared to fill it in.
*/
if (ofl->ofl_ossyminfo) {
} else
syminfo = 0;
/*
* Setup our string tables.
*/
/*
* Add the output file name to the first .symtab symbol.
*/
if (symtab) {
/* LINTED */
versym[1] = 0;
}
/*
* If we are to display GOT summary information, then allocate
* the buffer to 'cache' the GOT symbols into now.
*/
if (DBG_ENABLED) {
sizeof (Gottable))) == 0)
}
/*
* Traverse the program headers. Determine the last executable segment
* and the last data segment so that we can update etext and edata. If
* we have empty segments (reservations) record them for setting _end.
*/
}
/*
* Generate a section symbol for each output section.
*/
/* LINTED */
if (symtab) {
if (sectndx >= SHN_LORESERVE) {
} else {
/* LINTED */
}
}
if (versym)
}
/*
* Generate the .shstrtab for this section.
*/
/*
* Find the section index for our special symbols.
*/
/* LINTED */
/* LINTED */
}
}
if (start_set == 0) {
/* LINTED */
start_set++;
}
}
}
/*
* Add local register symbols to the .dynsym. These are required as
* DT_REGISTER .dynamic entries must have a symbol to reference.
*/
int ndx;
continue;
continue;
&stoff);
}
dynsym_ndx++;
}
}
/*
* Having traversed all the output segments, warn the user if the
* traditional text or data segments don't exist. Otherwise from these
* segments establish the values for `etext', `edata', `end', `END',
* and `START'.
*/
if (!(flags & FLG_OF_RELOBJ)) {
if (tsgp)
else {
etext_abs = 1;
}
if (dsgp) {
} else {
edata_abs = 1;
}
if (dsgp == 0) {
if (tsgp)
else
sgp = 0;
} else if (tsgp == 0)
else {
/*
* One of the segments must be of zero size.
*/
else
}
if (sgp) {
/*
* If the last loadable segment is a read-only segment,
* then the application which uses the symbol _end to
* find the beginning of writable heap area may cause
* segmentation violation. We adjust the value of the
* _end to skip to the next page boundary.
*
* 6401812 System interface which returs beginning
* heap would be nice.
* When the above RFE is implemented, the changes below
* could be changed in a better way.
*/
/*
* If we're dealing with a memory reservation there are
* no sections to establish an index for _end, so assign
* it as an absolute.
*/
/*
* Determine the last section for this segment.
*/
/* LINTED */
/* LINTED */
} else {
end_abs = 1;
}
} else {
end_abs = 1;
}
}
/*
* Initialize the scoped symbol table entry point. This is for all
* the global symbols that have been scoped to locals and will be
* filled in during global symbol processing so that we don't have
* to traverse the globals symbol hash array more than once.
*/
if (symtab) {
}
/*
* Assign .sunwdata1 information
*/
if (ofl->ofl_issunwdata1) {
/* LINTED */
}
/*
* If we are generating a .symtab collect all the local symbols,
* assigning a new virtual address or displacement (value).
*/
/*
* Check that we have local symbols to process. If the user
* has indicated scoping then scan the global symbols also
* looking for entries from this file to reduce to locals.
*/
continue;
unsigned char type;
/*
* Assign a got offset if necessary.
*/
/* nothing to do */
#else
#endif
if (DBG_ENABLED) {
_gottable++;
}
}
continue;
/*
* Ignore any symbols that have been marked as invalid
* during input processing. Providing these aren't used
* for relocation they'll just be dropped from the
* output image.
*/
continue;
/*
* If the section that this symbol was associated
* with has been discarded - then we discard
* the local symbol along with it.
*/
continue;
/*
* Generate an output symbol to represent this input
* symbol. Even if the symbol table is to be stripped
* we still need to update any local symbols that are
* used during relocation.
*/
_symshndx = 0;
(sdp->sd_psyminfo))) {
if (!dynsym)
/*
* Provided this isn't an unnamed register
* symbol, update its name.
*/
(void) st_setstring(strtab,
}
if (symshndx)
continue;
} else {
/*
* If this symbol requires modifying to provide
* for a relocation or move table update, make
* a copy of it.
*/
!(sdp->sd_psyminfo))
continue;
continue;
}
/*
* Update the symbols contents if necessary.
*/
continue;
}
/*
* If we are expanding the locally bound partially
* initialized symbols, then update the address here.
*/
if (ofl->ofl_issunwdata1 &&
else {
}
}
/*
* If this isn't an UNDEF symbol (ie. an input section
* is associated), update the symbols value and index.
*/
/* LINTED */
if (!(flags & FLG_OF_RELOBJ)) {
/*
* TLS symbols are relative to
* the TLS segment.
*/
}
/* LINTED */
if (_symshndx) {
}
} else {
/* LINTED */
}
}
}
}
/*
* Two special symbols are `_init' and `_fini'. If these are supplied
* by crti.o then they are used to represent the total concatenation of
* the `.init' and `.fini' sections. In this case determine the size of
* these sections and updated the symbols value accordingly.
*/
}
}
/*
* Assign .bss information for use with updating COMMON symbols.
*/
/* LINTED */
}
/*
* Assign .lbss information for use with updating LCOMMON symbols.
*/
if (ofl->ofl_islbss) {
/* LINTED */
}
#endif
/*
* Assign .tlsbss information for use with updating COMMON symbols.
*/
if (ofl->ofl_istlsbss) {
/* LINTED */
}
/*
* Assign .SUNWbss information for use with updating COMMON symbols.
*/
if (ofl->ofl_issunwbss) {
/* LINTED */
}
scndx = 0;
/*
* Traverse the internal symbol table updating information and
* allocating common.
*/
int local;
int restore;
/*
* Ignore any symbols that have been marked as
* invalid during input processing. Providing
* these aren't used for relocation they'll
* just be dropped from the output image.
*/
continue;
}
/*
* Only needed symbols will be copied to the
* output symbol table.
*/
continue;
(flags & FLG_OF_PROCRED))
local = 1;
else
local = 0;
} else {
ssndx++;
}
/*
* Note - we expand the COMMON symbols here
* because we *must* assign addresses to them
* in the same order that we calculated space
* in sym_validate(). If we don't then
* differing alignment requirements can
* throw us all out of whack.
*
* The expanded .bss global symbol is handled
* here as well.
*
* The actual adding entries into the symbol
* table still occurs below in hashbucket order.
*/
restore = 0;
/*
* If this this is an expanded symbol,
* it goes to sunwdata1.
*
* If this is a partial initialized
* global symbol and the output is a
* shared object, it goes to sunwbss.
*
* If allocating common assign it an
* address in the .bss section.
*
* Otherwise leave it as is.
*/
restore = 1;
restore = 1;
restore = 1;
restore = 1;
/*
* TLS symbols are relative to the TLS segment.
*/
}
restore = 1;
#endif
}
if (restore != 0) {
/*
* Make sure this COMMON
* symbol is returned to the
* same binding as was defined
* in the original relocatable
* object reference.
*/
bind = STB_GLOBAL;
else
}
}
if (ofl->ofl_hashbkts) {
(int (*)(const void *, const void *))sym_hash_compare);
}
const char *name;
int local = 0, enter_in_symtab;
sectndx = 0;
if (symtab)
enter_in_symtab = 1;
else
enter_in_symtab = 0;
/*
* Assign a got offset if necessary.
*/
/* nothing to do */
#else
#endif
if (DBG_ENABLED) {
_gottable++;
}
_gottable++;
}
}
/*
* If this symbol has been marked as being reduced to local
* scope then it will have to be placed in the scoped portion
* of the .symtab. Retain the appropriate index for use in
* version symbol indexing and relocation.
*/
(flags & FLG_OF_PROCRED)) {
local = 1;
else
enter_in_symtab = 0;
} else
/*
* Copy basic symbol and string information.
*/
/*
* If we require to record version symbol indexes, update the
* associated version symbol information for all defined
* symbols. If a version definition is required any zero value
* symbol indexes would have been flagged as undefined symbol
* errors, however if we're just scoping these need to fall into
* the base of global symbols.
*/
if ((vndx == 0) &&
if (symflags1 & FLG_SY1_ELIM)
else if (symflags1 & FLG_SY1_LOCL)
else
}
}
}
/*
* If we are creating the .syminfo section then set per symbol
* flags here.
*/
/*
* Identify a copy relocation symbol.
*/
/*
* A reference is bound to a needed dependency.
* Save this symbol descriptor, as its boundto
* element will need updating after the .dynamic
* section has been created. Flag whether this
* reference is lazy loadable, and if a direct
* binding is to be established.
*/
return (0);
/*
* Enable direct symbol bindings if:
*
* . Symbol was identified with the DIRECT
* keyword in a mapfile.
*
* . Symbol reference has been bound to a
* dependency which was specified as
* requiring direct bindings with -zdirect.
*
* . All symbol references are required to
* use direct bindings via -Bdirect.
*/
/*
* If this symbol has been explicitly defined
* as external, and remains unresolved, mark
* it as external.
*/
/*
* A reference to a parent object. Indicate
* whether a direct binding should be
* established.
*/
/*
* A filter definition. Although this symbol
* can only be a stub, it might be necessary to
* prevent external direct bindings.
*/
/*
* An auxiliary filter definition. By nature,
* this definition is direct, in that should the
* filtee lookup fail, we'll fall back to this
* object. It may still be necesssary to
* prevent external direct bindings.
*/
/*
* This definition exists within the object
* being created. Flag whether it is necessary
* to prevent external direct bindings.
*/
}
/*
* If external bindings are allowed, or this is
* a translator symbol, indicate the binding,
* and a direct binding if necessary.
*/
/*
* If this is a translator, the symbols
* boundto element will indicate the
* dependency to which it should resolve
* rather than itself. Save this info
* for updating after the .dynamic
* section has been created.
*/
if ((dtflags_1 & DF_1_TRANS) &&
return (0);
} else {
}
}
}
}
/*
* Note that the `sym' value is reset to be one of the new
* symbol table entries. This symbol will be updated further
* depending on the type of the symbol. Process the .symtab
* first, followed by the .dynsym, thus the `sym' value will
* remain as the .dynsym value when the .dynsym is present.
* This insures that any versioning symbols st_name value will
* be appropriate for the string table used to by version
* entries.
*/
if (enter_in_symtab) {
if (local)
else
}
/*
* Provided this isn't an unnamed register symbol,
* update its name and hash value.
*/
if (stoff) {
hashval =
/* LINTED */
_hashndx =
} else
}
}
}
continue;
} else
/*
* If we have a weak data symbol for which we need the real
* symbol also, save this processing until later.
*
* assigned to them. In that case we don't do the post-weak
* processing because the PLT's must be maintained so that we
* can do 'interpositioning' on both of the symbols.
*/
if ((sap->sa_linkndx) &&
if ((wkp =
if (enter_in_symtab)
if (local)
else
&symtab[symtab_ndx];
if (enter_in_symtab)
if (local)
scopesym_ndx++;
else
symtab_ndx++;
dynsym_ndx++;
continue;
}
}
/*
* assign new symbol value.
*/
}
/*
* Undefined weak global, if we are generating a static
* executable, output as an absolute zero. Otherwise
* leave it as is, ld.so.1 will skip symbols of this
* type (this technique allows applications and
* libraries to test for the existence of a symbol as an
* indication of the presence or absence of certain
* functionality).
*/
(FLG_OF_STATIC | FLG_OF_EXEC)) &&
}
(sectndx == SHN_COMMON)) {
/* COMMONs have already been processed */
/* EMPTY */
;
} else {
/* LINTED */
/*
* This is (or was) a COMMON symbol which was
* processed above - no processing
* required here.
*/
;
/*
* Make sure this undefined symbol is returned
* to the same binding as was defined in the
* original relocatable object reference.
*/
bind = STB_GLOBAL;
else
/* LINTED */
/*
* In an executable, the new symbol value is the
* old value (offset into defining section) plus
* virtual address of defining section. In a
* relocatable, the new value is the old value
* plus the displacement of the section within
* the file.
*/
/* LINTED */
if (!(flags & FLG_OF_RELOBJ)) {
/*
* TLS symbols are relative to
* the TLS segment.
*/
}
}
}
if (spec) {
switch (spec) {
case SDAUX_ID_ETEXT:
if (etext_abs)
else
break;
case SDAUX_ID_EDATA:
if (edata_abs)
else
break;
case SDAUX_ID_END:
if (end_abs)
else
break;
case SDAUX_ID_START:
break;
case SDAUX_ID_DYN:
if (flags & FLG_OF_DYNAMIC) {
/* LINTED */
}
break;
case SDAUX_ID_PLT:
/* LINTED */
}
break;
case SDAUX_ID_GOT:
/*
* Symbol bias for negative growing tables is
* stored in symbol's value during
* allocate_got().
*/
/* LINTED */
break;
default:
/* NOTHING */
;
}
}
/*
* If a plt index has been assigned to an undefined function,
* update the symbols value to the appropriate .plt address.
*/
!(flags & FLG_OF_BFLAG)) {
}
/*
* Finish updating the symbols.
*/
/*
* Sym Update: if scoped local - set local binding
*/
if (local)
/*
* Sym Updated: If both the .symtab and .dynsym
* are present then we've actually updated the information in
* the .dynsym, therefore copy this same information to the
* .symtab entry.
*/
}
if (enter_in_symtab) {
if (local)
_symndx = scopesym_ndx++;
else
_symndx = symtab_ndx++;
(sectndx >= SHN_LORESERVE)) {
} else {
/* LINTED */
}
}
(sectndx >= SHN_LORESERVE)) {
} else {
/* LINTED */
}
dynsym_ndx++;
}
}
/*
* Now that all the symbols have been processed update any weak symbols
* information (ie. copy all information except `st_name'). As both
* symbols will be represented in the output, return the weak symbol to
* its correct type.
*/
unsigned char bind;
/*
* If the symbol definition has been scoped then assign it to
* be local, otherwise if it's from a shared object then we need
* to maintain the binding of the original reference.
*/
if (flags & FLG_OF_PROCRED)
else
bind = STB_GLOBAL;
else
}
}
}
/*
* Now display GOT debugging information if required.
*/
/*
* Update the section headers information.
*/
if (symtab) {
/* LINTED */
if (symshndx) {
}
}
if (dynsym) {
/* LINTED */
/* LINTED */
if (dynshndx) {
}
}
/*
* Used by ld.so.1 only.
*/
return (etext);
}
/*
* Build the dynamic section.
*/
static int
{
/* LINTED */
continue;
/*
* Create and set up the DT_POSFLAG_1 entry here if required.
*/
dyn++;
}
else
continue;
/* LINTED */
sizeof (Dyn));
dyn++;
}
if (ofl->ofl_dtsfltrs) {
Dfltr_desc * dftp;
else
dyn++;
}
}
dyn++;
}
dyn++;
}
if (ofl->ofl_soname) {
dyn++;
}
if (ofl->ofl_filtees) {
if (flags & FLG_OF_AUX) {
} else {
}
dyn++;
}
dyn++;
dyn++;
}
if (ofl->ofl_config) {
dyn++;
}
if (ofl->ofl_depaudit) {
dyn++;
}
dyn++;
}
/*
* The following DT_* entries do not apply to relocatable objects.
*/
if (!(flags & FLG_OF_RELOBJ)) {
dyn++;
dyn++;
dyn++;
dyn++;
dyn++;
/*
* Reserve the DT_CHECKSUM entry. Its value will be filled in
* after the complete image is built.
*/
dyn++;
dyn++;
dyn++;
}
dyn++;
dyn++;
}
ofl->ofl_relocrelcnt) {
dyn++;
}
if (flags & FLG_OF_TEXTREL) {
/*
* Only the presence of this entry is used in this
* implementation, not the value stored.
*/
dyn++;
}
if (ofl->ofl_osfiniarray) {
dyn++;
dyn++;
}
if (ofl->ofl_osinitarray) {
dyn++;
dyn++;
}
if (ofl->ofl_ospreinitarray) {
dyn++;
dyn++;
}
if (ofl->ofl_pltcnt) {
dyn++;
dyn++;
dyn++;
}
if (ofl->ofl_pltpad) {
if (ofl->ofl_pltcnt)
else
dyn++;
dyn++;
}
if (ofl->ofl_relocsz) {
dyn++;
dyn++;
else
dyn++;
}
if (ofl->ofl_ossyminfo) {
dyn++;
dyn++;
dyn++;
}
if (ofl->ofl_osmove) {
dyn++;
dyn++;
dyn++;
}
if (ofl->ofl_regsymcnt) {
int ndx;
continue;
dyn++;
}
}
dyn++;
}
if (ofl->ofl_osinterp) {
dyn++;
}
if (ofl->ofl_osmove)
else
dyn++;
}
dyn++;
}
}
if (flags & FLG_OF_SYMBOLIC) {
dyn++;
}
dyn++;
/*
* If -Bdirect was specified, but some NODIRECT symbols were specified
* via a mapfile, or -znodirect was used on the command line, then
* clear the DF_1_DIRECT flag. The resultant object will use per-symbol
* direct bindings rather than be enabled for global direct bindings.
*/
dyn++;
return (1);
}
/*
* Build the version definition section
*/
static int
{
int num = 0;
/*
* Traverse the version descriptors and update the version structures
* to point to the dynstr name in preparation for building the version
* section structure.
*/
/*
* Create a new string table entry to represent the base
* version name (there is no corresponding symbol for
* this).
*/
/* LINTED */
} else {
/* LINTED */
}
} else {
/* LINTED */
}
}
/*
* Traverse the version descriptors and update the version section to
* reflect each version and its associated dependencies.
*/
/* LINTED */
vdap++;
/* LINTED */
/*
* Traverse this versions dependency list generating the
* appropriate version dependency entries.
*/
/* LINTED */
/* LINTED */
}
/*
* Record the versions auxiliary array offset and the associated
* dependency count.
*/
/* LINTED */
/*
* Record the next versions offset and update the version
* pointer. Remember the previous version offset as the very
* last structures next pointer should be null.
*/
/* LINTED */
}
/*
* Record the string table association with the version definition
* section, and the symbol table associated with the version symbol
* table (the actual contents of the version symbol table are filled
* in during symbol update).
*/
} else {
}
/* LINTED */
/* LINTED */
/*
* The version definition sections `info' field is used to indicate the
* number of entries in this section.
*/
return (1);
}
/*
* Build the version needed section
*/
static int
{
/*
* Traverse the shared object list looking for dependencies that have
* versions defined within them.
*/
continue;
/*
* If version needed definitions were specified in
* a mapfile ($VERSION=*) then record those
* definitions.
*/
(void) st_setstring(dynstr,
/* LINTED */
vnap++;
cnt++;
/* LINTED */
}
} else {
/*
* Traverse the version index list recording
* each version as a needed dependency.
*/
_cnt++) {
(void) st_setstring(dynstr,
} else {
}
/* LINTED */
}
}
}
/*
* Record the versions auxiliary array offset and
* the associated dependency count.
*/
/* LINTED */
/* LINTED */
/*
* Record the next versions offset and update the version
* pointer. Remember the previous version offset as the very
* last structures next pointer should be null.
*/
/* LINTED */
}
/*
* Record association on string table section and use the
* `info' field to indicate the number of entries in this
* section.
*/
/* LINTED */
return (1);
}
/*
* Update syminfo section.
*/
static uintptr_t
{
char *strtab;
Sfltr_desc * sftp;
} else {
}
/* LINTED */
if (ofl->ofl_osdynamic)
/* LINTED */
/*
* Update any references with the index into the dynamic table.
*/
else
}
/*
* Update any filtee references with the index into the dynamic table.
*/
Dfltr_desc * dftp;
/* LINTED */
}
/*
* Display debugging information about section.
*/
if (DBG_ENABLED) {
if (ofl->ofl_osdynamic)
else
dyn = 0;
/* LINTED */
}
}
return (1);
}
/*
* Build the output elf header.
*/
static uintptr_t
{
/*
* If an entry point symbol has already been established (refer
* sym_validate()) simply update the elf header entry point with the
* symbols value. If no entry point is defined it will have been filled
* with the start address of the first section within the text segment
* (refer update_outfile()).
*/
/*
* Note. it may be necessary to update the `e_flags' field in the
* machine dependent section.
*/
return (S_ERROR);
return (S_ERROR);
}
else
return (1);
}
/*
* Perform move table expansion.
*/
static uintptr_t
{
int i;
unsigned int stride;
/* LINTED */
/* LINTED */
case 1:
/* LINTED */
break;
case 2:
/* LINTED */
break;
case 4:
/* LINTED */
break;
case 8:
/* LINTED */
*((unsigned long long *)taddr) =
break;
default:
/*
* Should never come here since this is already
* checked at sunwmove_preprocess().
*/
return (S_ERROR);
}
}
return (1);
}
/*
* Update Move sections.
*/
static uintptr_t
{
/*
* Determine the index of the symbol table that will be referenced by
* the relocation entries.
*/
/* LINTED */
/* LINTED */
/*
* update sh_link and mv pointer for updating move table.
*/
if (ofl->ofl_osmove) {
}
/*
* Update symbol entry index
*/
/*
* Expand move table
*/
const char *s;
s = MSG_INTL(MSG_PSYM_EXPREASON1);
s = MSG_INTL(MSG_PSYM_EXPREASON2);
else
s = MSG_INTL(MSG_PSYM_EXPREASON3);
continue;
}
continue;
}
/*
* Process move table
*/
int idx = 1;
continue;
STB_LOCAL) {
/* LINTED */
STT_SECTION) {
}
} else {
/* LINTED */
}
} else {
STB_LOCAL) &&
/* LINTED */
} else {
if (isredloc)
/* LINTED */
}
}
mv1++;
idx++;
}
}
return (1);
}
/*
* Scan through the SHT_GROUP output sections. Update their
*/
static uintptr_t
{
/*
* Since input GROUP sections always create unique
* output GROUP sections - we know there is only one
* item on the list.
*/
/*
* Scan through the group data section and update
* all of the links to new values.
*/
for (i = 1; i < grpcnt; i++) {
/*
* Perform a sanity check that the section index
* stored in the SHT_GROUP section is valid
* for the file it came from.
*/
gdata[i] = 0;
continue;
}
/*
* If the referenced section didn't make it to the
* output file - just zero out the entry.
*/
gdata[i] = 0;
else
}
}
return (error);
}
static void
{
if (osp == 0)
return;
}
/*
* Translate the shdr->sh_{link, info} from its input section value to that
* of the corresponding shdr->sh_{link, info} output section value.
*/
static Word
{
/*
* Don't translate the special section numbers.
*/
if (link >= SHN_LORESERVE)
return (link);
/*
* Does this output section translate back to an input file. If not
* then there is no translation to do. In this case we will assume that
* if sh_link has a value, it's the right value.
*/
return (link);
/*
* Sanity check to make sure that the sh_{link, info} value
* is within range for the input file.
*/
return (link);
}
/*
* Follow the link to the input section.
*/
return (0);
return (0);
/* LINTED */
}
/*
* Having created all of the necessary sections, segments, and associated
* headers, fill in the program headers and update any other data in the
* output image. Some general rules:
*
* o If an interpretor is required always generate a PT_PHDR entry as
* well. It is this entry that triggers the kernel into passing the
* interpretor an aux vector instead of just a file descriptor.
*
* o When generating an image that will be interpreted (ie. a dynamic
* executable, a shared object, or a static executable that has been
* provided with an interpretor - weird, but possible), make the initial
* loadable segment include both the ehdr and phdr[]. Both of these
* tables are used by the interpretor therefore it seems more intuitive
* to explicitly defined them as part of the mapped image rather than
* relying on page rounding by the interpretor to allow their access.
*
* o When generating a static image that does not require an interpretor
* have the first loadable segment indicate the address of the first
* expect this behavior).
*/
{
/*
* Loop through the segment descriptors and pick out what we need.
*/
segndx++;
/*
* If an interpreter is required generate a PT_INTERP and
* PT_PHDR program header entry. The PT_PHDR entry describes
* the program header table itself. This information will be
* passed via the aux vector to the interpreter (ld.so.1).
* The program header array is actually part of the first
* loadable segment (and the PT_PHDR entry is the first entry),
* therefore its virtual address isn't known until the first
* loadable segment is processed.
*/
if (ofl->ofl_osinterp) {
}
continue;
}
if (ofl->ofl_osinterp) {
}
continue;
}
/*
* If we are creating a PT_SUNWDTRACE segment,
* just remember where the program header is.
*
* It's actual values will be assigned after
* update_osym() has completed and the symbol
* table addresses have been udpated.
*/
if ((ofl->ofl_dtracesym) &&
((flags & FLG_OF_RELOBJ) == 0)) {
}
continue;
}
/*
* generate the PT_SUNWCAP header. Note, as this comes before
* the first loadable segment, we don't yet know its real
* virtual address. This is updated later.
*/
}
continue;
}
/*
* As the dynamic program header occurs after the loadable
* headers in the segment descriptor table, all the address
* information for the .dynamic output section will have been
* figured out by now.
*/
}
continue;
}
if (ofl->ofl_unwindhdr == 0)
continue;
continue;
}
#endif
continue;
if (firstshdr == 0) {
continue;
}
else
}
continue;
}
/*
* If this is an empty segment declaration, it will occur after
* all other loadable segments, make sure the previous segment
* doesn't overlap. We do not do the check if we are generating
* a relocatable file.
*/
int i;
continue;
/*
* Check overlaps
*/
for (i = 0; i < phdrndx - 1; i++) {
continue;
}
continue;
}
/*
* Having processed any of the special program headers any
* remaining headers will be built to express individual
* segments. Segments are only built if they have output
* section descriptors associated with them (ie. some form of
* input section has been matched to this segment).
*/
continue;
/*
* Determine the segments offset and size from the section
* information provided from elf_update().
* Allow for multiple NOBITS sections.
*/
p_align = 0;
if (nobits) {
return (S_ERROR);
}
}
/*
* If this is PT_SUNWBSS, set alignment
*/
/*
* If this is the first loadable segment of a dynamic object,
* or an interpretor has been specified (a static object built
* with an interpretor will still be given a PT_HDR entry), then
* compensate for the elf header and program header array. Both
* of these are actually part of the loadable segment as they
* may be inspected by the interpretor. Adjust the segments
* size and offset accordingly.
*/
}
/*
* If a segment size symbol is required (specified via a
* mapfile) update its value.
*/
/*
* If no file content has been assigned to this segment (it
* only contains no-bits sections), then reset the offset for
* consistency.
*/
/*
* If a virtual address has been specified for this segment
* (presumably from a map file) use it and make sure the
* previous segment does not run into this segment.
*/
} else {
}
}
/*
* Adjust the address offset and p_align if needed.
*/
else
}
/*
* If an interpreter is required set the virtual address of the
* PT_PHDR program header now that we know the virtual address
* of the loadable segment that contains it. Update the
* PT_SUNWCAP header similarly.
*/
if (ofl->ofl_osinterp)
/*
* Finally, if we're creating a dynamic object
* (or a static object in which an interpretor
* is specified) update the vaddr to reflect
* the address of the first section within this
* segment.
*/
if ((ofl->ofl_osinterp) ||
(flags & FLG_OF_DYNAMIC))
} else {
/*
* If the DF_1_NOHDR flag was set, PT_PHDR
* will not be part of any loadable segment.
*/
}
}
/*
* Save the address of the first executable section for default
* use as the execution entry point. This may get overridden in
* update_oehdr().
*/
/*
* Traverse the output section descriptors for this segment so
* that we can update the section headers addresses. We've
* calculated the virtual address of the initial section within
* this segment, so each successive section can be calculated
* based on their offsets from each other.
*/
secndx = 0;
hshdr = 0;
if (!(flags & FLG_OF_RELOBJ) &&
if (hshdr)
}
secndx++;
}
/*
* Establish the virtual address of the end of the last section
* in this segment so that the next segments offset can be
* calculated from this.
*/
if (hshdr)
/*
* Output sections for this segment complete. Adjust the
* virtual offset for the last sections size, and make sure we
* haven't exceeded any maximum segment length specification.
*/
return (S_ERROR);
}
}
}
/*
* Update any new output sections. When building the initial output
* image, a number of sections were created but left uninitialized (eg.
* .dynsym, .dynstr, .symtab, .symtab, etc.). Here we update these
* sections with the appropriate data. Other sections may still be
* modified via reloc_process().
*
* Copy the interpretor name into the .interp section.
*/
if (ofl->ofl_interp)
ofl->ofl_interp);
/*
* Update the .shstrtab, .strtab and .dynstr sections.
*/
/*
* Build any output symbol tables, the symbols information is copied
* and updated into the new output image.
*/
return (S_ERROR);
/*
* If we have a PT_SUNWDTRACE phdr, update it now with the address of
* the symbol. It's only now been updated via update_sym().
*/
/*
* Take permisions of the segment the symbol is associated with.
*/
}
/*
* Update the GROUP sections.
*/
return (S_ERROR);
/*
* Update Move Table.
*/
return (S_ERROR);
}
/*
* Build any output headers, version information, dynamic structure and
* syminfo structure.
*/
return (S_ERROR);
return (S_ERROR);
return (S_ERROR);
if (flags & FLG_OF_DYNAMIC) {
return (S_ERROR);
if (ofl->ofl_ossyminfo)
return (S_ERROR);
}
/*
* Emit Strtab diagnostics.
*/
ofl->ofl_shdrsttab));
ofl->ofl_strtab));
ofl->ofl_dynstrtab));
/*
* Initialize the section headers string table index within the elf
* header.
*/
/* LINTED */
/* LINTED */
} else {
/*
* If the STRTAB section index doesn't fit into
* e_shstrndx, then we store it in 'shdr[0].st_link'.
*/
return (S_ERROR);
}
return (S_ERROR);
}
}
}