The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/amd64/amd64/elf_machdep.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright 1996-1998 John D. Polstra.
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  *
   14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   24  *
   25  * $FreeBSD: releng/5.1/sys/amd64/amd64/elf_machdep.c 114919 2003-05-11 22:40:25Z peter $
   26  */
   27 
   28 #include <sys/param.h>
   29 #include <sys/kernel.h>
   30 #include <sys/systm.h>
   31 #include <sys/exec.h>
   32 #include <sys/imgact.h>
   33 #include <sys/linker.h>
   34 #include <sys/sysent.h>
   35 #include <sys/imgact_elf.h>
   36 #include <sys/syscall.h>
   37 #include <sys/signalvar.h>
   38 #include <sys/vnode.h>
   39 
   40 #include <vm/vm.h>
   41 #include <vm/pmap.h>
   42 #include <vm/vm_param.h>
   43 
   44 #include <machine/elf.h>
   45 #include <machine/md_var.h>
   46 
   47 struct sysentvec elf64_freebsd_sysvec = {
   48         SYS_MAXSYSCALL,
   49         sysent,
   50         0,
   51         0,
   52         NULL,
   53         0,
   54         NULL,
   55         NULL,
   56         __elfN(freebsd_fixup),
   57         sendsig,
   58         sigcode,
   59         &szsigcode,
   60         NULL,
   61         "FreeBSD ELF64",
   62         __elfN(coredump),
   63         NULL,
   64         MINSIGSTKSZ,
   65         PAGE_SIZE,
   66         VM_MIN_ADDRESS,
   67         VM_MAXUSER_ADDRESS,
   68         USRSTACK,
   69         PS_STRINGS,
   70         VM_PROT_ALL,
   71         exec_copyout_strings,
   72         exec_setregs
   73 };
   74 
   75 static Elf64_Brandinfo freebsd_brand_info = {
   76                                                 ELFOSABI_FREEBSD,
   77                                                 EM_X86_64,
   78                                                 "FreeBSD",
   79                                                 "",
   80                                                 "/usr/libexec/ld-elf.so.1",
   81                                                 &elf64_freebsd_sysvec
   82                                           };
   83 
   84 SYSINIT(elf64, SI_SUB_EXEC, SI_ORDER_ANY,
   85         (sysinit_cfunc_t) elf64_insert_brand_entry,
   86         &freebsd_brand_info);
   87 
   88 /* Process one elf relocation with addend. */
   89 static int
   90 elf_reloc_internal(linker_file_t lf, const void *data, int type, int local)
   91 {
   92         Elf_Addr relocbase = (Elf_Addr) lf->address;
   93         Elf_Addr *where;
   94         Elf_Addr addr;
   95         Elf_Addr addend;
   96         Elf_Word rtype, symidx;
   97         const Elf_Rel *rel;
   98         const Elf_Rela *rela;
   99 
  100         switch (type) {
  101         case ELF_RELOC_REL:
  102                 rel = (const Elf_Rel *)data;
  103                 where = (Elf_Addr *) (relocbase + rel->r_offset);
  104                 addend = *where;
  105                 rtype = ELF_R_TYPE(rel->r_info);
  106                 symidx = ELF_R_SYM(rel->r_info);
  107                 break;
  108         case ELF_RELOC_RELA:
  109                 rela = (const Elf_Rela *)data;
  110                 where = (Elf_Addr *) (relocbase + rela->r_offset);
  111                 addend = rela->r_addend;
  112                 rtype = ELF_R_TYPE(rela->r_info);
  113                 symidx = ELF_R_SYM(rela->r_info);
  114                 break;
  115         default:
  116                 panic("unknown reloc type %d\n", type);
  117         }
  118 
  119         if (local) {
  120                 if (rtype == R_X86_64_RELATIVE) {       /* A + B */
  121                         addr = relocbase + addend;
  122                         if (*where != addr)
  123                                 *where = addr;
  124                 }
  125                 return (0);
  126         }
  127 
  128         switch (rtype) {
  129 
  130                 case R_X86_64_NONE:     /* none */
  131                         break;
  132 
  133                 case R_X86_64_64:               /* S + A */
  134                         addr = elf_lookup(lf, symidx, 1);
  135                         if (addr == 0)
  136                                 return -1;
  137                         addr += addend;
  138                         if (*where != addr)
  139                                 *where = addr;
  140                         break;
  141 
  142                 case R_X86_64_PC32:     /* S + A - P */
  143                         addr = elf_lookup(lf, symidx, 1);
  144                         if (addr == 0)
  145                                 return -1;
  146                         addr += addend - (Elf_Addr)where;
  147                         /* XXX needs to be 32 bit *where, not 64 bit */
  148                         if (*where != addr)
  149                                 *where = addr;
  150                         break;
  151 
  152                 case R_X86_64_COPY:     /* none */
  153                         /*
  154                          * There shouldn't be copy relocations in kernel
  155                          * objects.
  156                          */
  157                         printf("kldload: unexpected R_COPY relocation\n");
  158                         return -1;
  159                         break;
  160 
  161                 case R_X86_64_GLOB_DAT: /* S */
  162                         addr = elf_lookup(lf, symidx, 1);
  163                         if (addr == 0)
  164                                 return -1;
  165                         if (*where != addr)
  166                                 *where = addr;
  167                         break;
  168 
  169                 case R_X86_64_RELATIVE: /* B + A */
  170                         break;
  171 
  172                 default:
  173                         printf("kldload: unexpected relocation type %ld\n",
  174                                rtype);
  175                         return -1;
  176         }
  177         return(0);
  178 }
  179 
  180 int
  181 elf_reloc(linker_file_t lf, const void *data, int type)
  182 {
  183 
  184         return (elf_reloc_internal(lf, data, type, 0));
  185 }
  186 
  187 int
  188 elf_reloc_local(linker_file_t lf, const void *data, int type)
  189 {
  190 
  191         return (elf_reloc_internal(lf, data, type, 1));
  192 }
  193 
  194 int
  195 elf_cpu_load_file(linker_file_t lf __unused)
  196 {
  197 
  198         return (0);
  199 }
  200 
  201 int
  202 elf_cpu_unload_file(linker_file_t lf __unused)
  203 {
  204 
  205         return (0);
  206 }

Cache object: 8a58935a8dc26153a60a6a47cbbb38e6


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.