entry.c revision ba2be53024c0b999e74ba9adcd7d80fec5df8c57
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#define ELF_TARGET_AMD64
#include <stdio.h>
#include <memory.h>
#include <debug.h>
#include "msg.h"
#include "_libld.h"
/*
* Types of segment index.
*/
typedef enum {
#if defined(_ELF64)
LD_LRODATA, /* (amd64-only) */
LD_LDATA, /* (amd64-only) */
#endif
#if defined(_ELF64)
LD_UNWIND, /* (amd64-only) */
#endif
} Segment_ndx;
/*
* The loader uses a `segment descriptor' list to describe the output
* segments it can potentially create. This list is initially seeded
* using the templates contained in the sg_desc[] array below. Additional
* segments may be added using a map file.
*
* The entries in sg_desc[] must be put in the order defined by the
* Segment_ndx enum, such that a given LD_XXX value can serve as
* an index into sg_desc[] for the corresponding descriptor.
*
* The entries in sg_desc[] are initialized using the SG_DESC_INIT macro
* for two reasons:
*
* 1) The first field of the Sg_desc struct is a program header
* entry. ELF32_Phdr and ELF64_Phdr have the same fields,
* but their order is different. Use of a macro allows us
* to handle this transparently.
* 2) Most of the fields in the Sg_desc entries are set to 0.
* Use of a macro allows us to hide the clutter.
*/
#ifdef _ELF64
#else
#endif
/* LD_PHDR */
(FLG_SG_TYPE | FLG_SG_FLAGS)),
/* LD_INTERP */
(FLG_SG_TYPE | FLG_SG_FLAGS)),
/* LD_SUNWCAP */
(FLG_SG_TYPE | FLG_SG_FLAGS)),
/* LD_TEXT */
(FLG_SG_TYPE | FLG_SG_FLAGS)),
/* LD_DATA */
(FLG_SG_TYPE | FLG_SG_FLAGS)),
/* LD_BSS */
#if defined(_ELF64)
/* LD_LRODATA (amd64-only) */
(FLG_SG_TYPE | FLG_SG_FLAGS)),
/* LD_LDATA (amd64-only) */
(FLG_SG_TYPE | FLG_SG_FLAGS)),
#endif
/* LD_DYN */
(FLG_SG_TYPE | FLG_SG_FLAGS)),
/* LD_DTRACE */
/* LD_SUNWBSS */
/* LD_TLS */
(FLG_SG_TYPE | FLG_SG_FLAGS)),
#if defined(_ELF64)
/* LD_UNWIND (amd64-only) */
(FLG_SG_TYPE | FLG_SG_FLAGS)),
#endif
/* LD_NOTE */
/* LD_EXTRA */
};
/*
* The input processing of the loader involves matching the sections of its
* input files to an `entrance descriptor definition'. The entrance criteria
* is different for either a static or dynamic linkage, and may even be
* modified further using a map file. Each entrance criteria is associated
* with a segment descriptor, thus a mapping of input sections to output
* segments is maintained.
*
* Note the trick used for the ec_segment field, which is supposed to
* be a pointer to a segment descriptor. We initialize this with the
* index of the descriptor, and then turn it into an actual pointer
* at runtime, once memory has been allocated and the templates copied.
*/
#if defined(_ELF64) /* (amd64-only) */
#endif
#if defined(_ELF64) /* (amd64-only) */
#endif
};
/*
* Initialize new entrance and segment descriptors and add them as lists to
* the output file descriptor.
*/
{
/*
* Initialize the elf library.
*/
return (S_ERROR);
}
/*
* Initialize internal Global Symbol Table AVL tree
*/
/*
* Allocate and initialize writable copies of both the entrance and
* segment descriptors.
*
* Note that on non-amd64 targets, this allocates a few more
* elements than are needed. For now, we are willing to overallocate
* a small amount to simplify the code.
*/
return (S_ERROR);
return (S_ERROR);
/*
* The data segment permissions can differ:
*
* - Architecural/ABI per-platform differences
* - Whether the object is built statically or dynamically
*
* Those segments so affected have their program header flags
* set here at runtime, rather than in the sg_desc templates above.
*/
#if defined(_ELF64)
#endif
} else {
}
/*
* Traverse the new entrance descriptor list converting the segment
* pointer entries to the absolute address within the new segment
* descriptor list. Add each entrance descriptor to the output file
* list.
*/
#if defined(_ELF64)
/* Don't use the amd64 entry conditions for non-amd64 targets */
continue;
#endif
return (S_ERROR);
}
/*
* Traverse the new segment descriptor list adding each entry to the
* segment descriptor list. For each loadable segment initialize
* a default alignment (ld(1) and ld.so.1 initialize this differently).
*/
#if defined(_ELF64)
/* Ignore amd64 segment templates for non-amd64 targets */
switch (idx) {
case LD_LRODATA:
case LD_LDATA:
case LD_UNWIND:
continue;
}
#endif
return (S_ERROR);
}
return (1);
}