Subversion Repositories HelenOS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2008 Jiri Svoboda
  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.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup rtld rtld
  30.  * @brief
  31.  * @{
  32.  */
  33. /**
  34.  * @file
  35.  */
  36.  
  37. #include <stdio.h>
  38.  
  39. #include <arch.h>
  40. #include <elf_dyn.h>
  41. #include <rtld.h>
  42.  
  43. /**
  44.  * Process (fixup) all relocations in a relocation table.
  45.  */
  46. void rel_table_process(module_t *m, elf_rel_t *rt, size_t rt_size)
  47. {
  48.     unsigned bias;
  49.     int i;
  50.  
  51.     size_t rt_entries;
  52.     size_t r_offset;
  53.     elf_word r_info;
  54.     unsigned rel_type;
  55.     elf_word sym_idx;
  56. //  uintptr_t sym_addr;
  57.    
  58.     elf_symbol_t *sym_table;
  59.     elf_symbol_t *sym;
  60.     uint32_t *r_ptr;
  61.     char *str_tab;
  62.  
  63.     printf("parse relocation table\n");
  64.  
  65.     sym_table = m->dyn.sym_tab;
  66.     bias = m->bias;
  67.     rt_entries = rt_size / sizeof(elf_rel_t);
  68.     str_tab = m->dyn.str_tab;
  69.  
  70.     printf("address: 0x%x, entries: %d\n", (uintptr_t)rt, rt_entries);
  71.    
  72.     for (i = 0; i < rt_entries; ++i) {
  73.         printf("symbol %d: ", i);
  74.         r_offset = rt[i].r_offset;
  75.         r_info = rt[i].r_info;
  76.  
  77.         sym_idx = ELF32_R_SYM(r_info);
  78.         sym = &sym_table[sym_idx];
  79.  
  80.         printf("name '%s', value 0x%x, size 0x%x\n",
  81.             str_tab + sym->st_name,
  82.             sym->st_value,
  83.             sym->st_size);
  84.  
  85.         rel_type = ELF32_R_TYPE(r_info);
  86.         r_ptr = (uint32_t *)(r_offset + bias);
  87.  
  88.         printf("rel_type: %x, rel_offset: 0x%x\n", rel_type, r_offset);
  89. /*
  90.         switch (rel_type) {
  91.         case R_386_GLOB_DAT:
  92.         case R_386_JUMP_SLOT:
  93.             sym_addr = sym_table[sym_idx].st_value + bias;
  94.             kputint(sym_idx);
  95.             kputint(sym_addr);
  96.  
  97.             *r_ptr = sym_addr;
  98.             break;
  99.  
  100.         case R_386_32:
  101.             sym_addr = sym_table[sym_idx].st_value + bias;
  102.             kputint(sym_idx);
  103.             kputint(sym_addr);
  104.  
  105.             *r_ptr += sym_addr;
  106.             break;
  107.            
  108.         case R_386_RELATIVE:
  109.             *r_ptr += bias;
  110.             break;
  111.         }*/
  112.     }
  113.  
  114. }
  115.  
  116. /** @}
  117.  */
  118.