diff options
author | peter <peter@FreeBSD.org> | 1998-10-16 03:55:01 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1998-10-16 03:55:01 +0000 |
commit | 464de37ce6099f409aa233200a94ac38216aa211 (patch) | |
tree | 59ed738c6bca93117593ea63241912064597c130 /sys/amd64 | |
parent | ad0030e392049cd4f887968f40988dd6cf5e5ee0 (diff) | |
download | FreeBSD-src-464de37ce6099f409aa233200a94ac38216aa211.zip FreeBSD-src-464de37ce6099f409aa233200a94ac38216aa211.tar.gz |
*gulp*. Jordan specifically OK'ed this..
This is the bulk of the support for doing kld modules. Two linker_sets
were replaced by SYSINIT()'s. VFS's and exec handlers are self registered.
kld is now a superset of lkm. I have converted most of them, they will
follow as a seperate commit as samples.
This all still works as a static a.out kernel using LKM's.
Diffstat (limited to 'sys/amd64')
-rw-r--r-- | sys/amd64/amd64/elf_machdep.c | 60 |
1 files changed, 43 insertions, 17 deletions
diff --git a/sys/amd64/amd64/elf_machdep.c b/sys/amd64/amd64/elf_machdep.c index ffa914a..eae2f4f 100644 --- a/sys/amd64/amd64/elf_machdep.c +++ b/sys/amd64/amd64/elf_machdep.c @@ -22,7 +22,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: elf_machdep.c,v 1.1 1998/10/09 20:35:45 peter Exp $ + * $Id: elf_machdep.c,v 1.2 1998/10/09 20:38:03 peter Exp $ */ #include <sys/param.h> @@ -38,38 +38,61 @@ /* Process one elf relocation with addend. */ int -elf_reloc(linker_file_t lf, const Elf_Rela *rela, const char *sym) +elf_reloc(linker_file_t lf, const void *data, int type, const char *sym) { Elf_Addr relocbase = (Elf_Addr) lf->address; - Elf_Addr *where = (Elf_Addr *) (relocbase + rela->r_offset); + Elf_Addr *where; Elf_Addr addr, tmp_value; + Elf_Addr addend; + Elf_Word rtype; + const Elf_Rel *rel; + const Elf_Rela *rela; - switch (ELF_R_TYPE(rela->r_info)) { + switch (type) { + case ELF_RELOC_REL: + rel = (Elf_Rel *)data; + where = (Elf_Addr *) (relocbase + rel->r_offset); + addend = *where; + rtype = ELF_R_TYPE(rel->r_info); + break; + case ELF_RELOC_RELA: + rela = (Elf_Rela *)data; + where = (Elf_Addr *) (relocbase + rela->r_offset); + addend = rela->r_addend; + rtype = ELF_R_TYPE(rela->r_info); + break; + default: + panic("unknown reloc type %d\n", type); + } + + switch (rtype) { - case R_386_NONE: + case R_386_NONE: /* none */ break; - case R_386_32: + case R_386_32: /* S + A */ + if (sym == NULL) + return -1; addr = (Elf_Addr)linker_file_lookup_symbol(lf, sym, 1); if (addr == NULL) return -1; - - addr += rela->r_addend; + addr += addend; if (*where != addr) *where = addr; break; - case R_386_PC32: + case R_386_PC32: /* S + A - P */ + if (sym == NULL) + return -1; addr = (Elf_Addr)linker_file_lookup_symbol(lf, sym, 1); if (addr == NULL) return -1; - - addr += *where - (Elf_Addr)where + rela->r_addend; + addr += addend - (Elf_Addr)where; if (*where != addr) *where = addr; break; - case R_386_COPY: + case R_386_COPY: /* none */ /* * There shouldn't be copy relocations in kernel * objects. @@ -78,22 +101,25 @@ elf_reloc(linker_file_t lf, const Elf_Rela *rela, const char *sym) return -1; break; - case R_386_GLOB_DAT: + case R_386_GLOB_DAT: /* S */ + if (sym == NULL) + return -1; addr = (Elf_Addr)linker_file_lookup_symbol(lf, sym, 1); if (addr == NULL) return -1; - if (*where != addr) *where = addr; break; - case R_386_RELATIVE: - *where += relocbase; + case R_386_RELATIVE: /* B + A */ + addr = relocbase + addend; + if (*where != addr) + *where = addr; break; default: printf("kldload: unexpected relocation type %d\n", - ELF_R_TYPE(rela->r_info)); + rtype); return -1; } return(0); |