ia64/xen-unstable

changeset 13919:58e71ae679d5

libelf: use xen code style.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Wed Feb 14 16:06:10 2007 +0000 (2007-02-14)
parents 3f63c1825b0d
children 9af0c7e4ff51
files xen/common/libelf/libelf-dominfo.c xen/common/libelf/libelf-loader.c xen/common/libelf/libelf-private.h xen/common/libelf/libelf-relocate.c xen/common/libelf/libelf-tools.c
line diff
     1.1 --- a/xen/common/libelf/libelf-dominfo.c	Wed Feb 14 16:05:28 2007 +0000
     1.2 +++ b/xen/common/libelf/libelf-dominfo.c	Wed Feb 14 16:06:10 2007 +0000
     1.3 @@ -15,61 +15,63 @@ const char *elf_xen_feature_names[] = {
     1.4      [XENFEAT_pae_pgdir_above_4gb] = "pae_pgdir_above_4gb"
     1.5  };
     1.6  const int elf_xen_features =
     1.7 -    sizeof(elf_xen_feature_names) / sizeof(elf_xen_feature_names[0]);
     1.8 +sizeof(elf_xen_feature_names) / sizeof(elf_xen_feature_names[0]);
     1.9  
    1.10  int elf_xen_parse_features(const char *features,
    1.11 -			   uint32_t *supported,
    1.12 -			   uint32_t *required)
    1.13 +                           uint32_t *supported,
    1.14 +                           uint32_t *required)
    1.15  {
    1.16      char feature[64];
    1.17      int pos, len, i;
    1.18  
    1.19 -    if (NULL == features)
    1.20 -	return 0;
    1.21 -    for (pos = 0; features[pos] != '\0'; pos += len)
    1.22 -    {
    1.23 -	memset(feature, 0, sizeof(feature));
    1.24 -	for (len = 0;; len++)
    1.25 -	{
    1.26 -	    if (len >= sizeof(feature)-1)
    1.27 -		break;
    1.28 -	    if (features[pos + len] == '\0')
    1.29 -		break;
    1.30 -	    if (features[pos + len] == '|')
    1.31 -	    {
    1.32 -		len++;
    1.33 -		break;
    1.34 -	    }
    1.35 -	    feature[len] = features[pos + len];
    1.36 -	}
    1.37 +    if ( features == NULL )
    1.38 +        return 0;
    1.39  
    1.40 -	for (i = 0; i < elf_xen_features; i++)
    1.41 -	{
    1.42 -	    if (!elf_xen_feature_names[i])
    1.43 -		continue;
    1.44 -	    if (NULL != required && feature[0] == '!')
    1.45 -	    {
    1.46 -		/* required */
    1.47 -		if (0 == strcmp(feature + 1, elf_xen_feature_names[i]))
    1.48 -		{
    1.49 -		    elf_xen_feature_set(i, supported);
    1.50 -		    elf_xen_feature_set(i, required);
    1.51 -		    break;
    1.52 -		}
    1.53 -	    }
    1.54 -	    else
    1.55 -	    {
    1.56 -		/* supported */
    1.57 -		if (0 == strcmp(feature, elf_xen_feature_names[i]))
    1.58 -		{
    1.59 -		    elf_xen_feature_set(i, supported);
    1.60 -		    break;
    1.61 -		}
    1.62 -	    }
    1.63 -	}
    1.64 -	if (i == elf_xen_features)
    1.65 -	    return -1;
    1.66 +    for ( pos = 0; features[pos] != '\0'; pos += len )
    1.67 +    {
    1.68 +        memset(feature, 0, sizeof(feature));
    1.69 +        for ( len = 0;; len++ )
    1.70 +        {
    1.71 +            if ( len >= sizeof(feature)-1 )
    1.72 +                break;
    1.73 +            if ( features[pos + len] == '\0' )
    1.74 +                break;
    1.75 +            if ( features[pos + len] == '|' )
    1.76 +            {
    1.77 +                len++;
    1.78 +                break;
    1.79 +            }
    1.80 +            feature[len] = features[pos + len];
    1.81 +        }
    1.82 +
    1.83 +        for ( i = 0; i < elf_xen_features; i++ )
    1.84 +        {
    1.85 +            if ( !elf_xen_feature_names[i] )
    1.86 +                continue;
    1.87 +            if ( (required != NULL) && (feature[0] == '!') )
    1.88 +            {
    1.89 +                /* required */
    1.90 +                if ( !strcmp(feature + 1, elf_xen_feature_names[i]) )
    1.91 +                {
    1.92 +                    elf_xen_feature_set(i, supported);
    1.93 +                    elf_xen_feature_set(i, required);
    1.94 +                    break;
    1.95 +                }
    1.96 +            }
    1.97 +            else
    1.98 +            {
    1.99 +                /* supported */
   1.100 +                if ( !strcmp(feature, elf_xen_feature_names[i]) )
   1.101 +                {
   1.102 +                    elf_xen_feature_set(i, supported);
   1.103 +                    break;
   1.104 +                }
   1.105 +            }
   1.106 +        }
   1.107 +        if ( i == elf_xen_features )
   1.108 +            return -1;
   1.109      }
   1.110 +
   1.111      return 0;
   1.112  }
   1.113  
   1.114 @@ -77,26 +79,26 @@ int elf_xen_parse_features(const char *f
   1.115  /* xen elf notes                                                            */
   1.116  
   1.117  int elf_xen_parse_note(struct elf_binary *elf,
   1.118 -		       struct elf_dom_parms *parms,
   1.119 -		       const elf_note *note)
   1.120 +                       struct elf_dom_parms *parms,
   1.121 +                       const elf_note *note)
   1.122  {
   1.123  /* *INDENT-OFF* */
   1.124      static const struct {
   1.125 -	char *name;
   1.126 -	int str;
   1.127 +        char *name;
   1.128 +        int str;
   1.129      } note_desc[] = {
   1.130 -	[XEN_ELFNOTE_ENTRY] = { "ENTRY", 0},
   1.131 -	[XEN_ELFNOTE_HYPERCALL_PAGE] = { "HYPERCALL_PAGE", 0},
   1.132 -	[XEN_ELFNOTE_VIRT_BASE] = { "VIRT_BASE", 0},
   1.133 -	[XEN_ELFNOTE_PADDR_OFFSET] = { "PADDR_OFFSET", 0},
   1.134 -	[XEN_ELFNOTE_HV_START_LOW] = { "HV_START_LOW", 0},
   1.135 -	[XEN_ELFNOTE_XEN_VERSION] = { "XEN_VERSION", 1},
   1.136 -	[XEN_ELFNOTE_GUEST_OS] = { "GUEST_OS", 1},
   1.137 -	[XEN_ELFNOTE_GUEST_VERSION] = { "GUEST_VERSION", 1},
   1.138 -	[XEN_ELFNOTE_LOADER] = { "LOADER", 1},
   1.139 -	[XEN_ELFNOTE_PAE_MODE] = { "PAE_MODE", 1},
   1.140 -	[XEN_ELFNOTE_FEATURES] = { "FEATURES", 1},
   1.141 -	[XEN_ELFNOTE_BSD_SYMTAB] = { "BSD_SYMTAB", 1},
   1.142 +        [XEN_ELFNOTE_ENTRY] = { "ENTRY", 0},
   1.143 +        [XEN_ELFNOTE_HYPERCALL_PAGE] = { "HYPERCALL_PAGE", 0},
   1.144 +        [XEN_ELFNOTE_VIRT_BASE] = { "VIRT_BASE", 0},
   1.145 +        [XEN_ELFNOTE_PADDR_OFFSET] = { "PADDR_OFFSET", 0},
   1.146 +        [XEN_ELFNOTE_HV_START_LOW] = { "HV_START_LOW", 0},
   1.147 +        [XEN_ELFNOTE_XEN_VERSION] = { "XEN_VERSION", 1},
   1.148 +        [XEN_ELFNOTE_GUEST_OS] = { "GUEST_OS", 1},
   1.149 +        [XEN_ELFNOTE_GUEST_VERSION] = { "GUEST_VERSION", 1},
   1.150 +        [XEN_ELFNOTE_LOADER] = { "LOADER", 1},
   1.151 +        [XEN_ELFNOTE_PAE_MODE] = { "PAE_MODE", 1},
   1.152 +        [XEN_ELFNOTE_FEATURES] = { "FEATURES", 1},
   1.153 +        [XEN_ELFNOTE_BSD_SYMTAB] = { "BSD_SYMTAB", 1},
   1.154      };
   1.155  /* *INDENT-ON* */
   1.156  
   1.157 @@ -104,73 +106,73 @@ int elf_xen_parse_note(struct elf_binary
   1.158      uint64_t val = 0;
   1.159      int type = elf_uval(elf, note, type);
   1.160  
   1.161 -    if ((type >= sizeof(note_desc) / sizeof(note_desc[0])) ||
   1.162 -	(NULL == note_desc[type].name))
   1.163 +    if ( (type >= sizeof(note_desc) / sizeof(note_desc[0])) ||
   1.164 +         (note_desc[type].name == NULL) )
   1.165      {
   1.166 -	elf_msg(elf, "%s: unknown xen elf note (0x%x)\n",
   1.167 -		__FUNCTION__, type);
   1.168 -	return 0;
   1.169 +        elf_msg(elf, "%s: unknown xen elf note (0x%x)\n",
   1.170 +                __FUNCTION__, type);
   1.171 +        return 0;
   1.172      }
   1.173  
   1.174 -    if (note_desc[type].str)
   1.175 +    if ( note_desc[type].str )
   1.176      {
   1.177 -	str = elf_note_desc(elf, note);
   1.178 -	elf_msg(elf, "%s: %s = \"%s\"\n", __FUNCTION__,
   1.179 -		note_desc[type].name, str);
   1.180 +        str = elf_note_desc(elf, note);
   1.181 +        elf_msg(elf, "%s: %s = \"%s\"\n", __FUNCTION__,
   1.182 +                note_desc[type].name, str);
   1.183      }
   1.184      else
   1.185      {
   1.186 -	val = elf_note_numeric(elf, note);
   1.187 -	elf_msg(elf, "%s: %s = 0x%" PRIx64 "\n", __FUNCTION__,
   1.188 -		note_desc[type].name, val);
   1.189 +        val = elf_note_numeric(elf, note);
   1.190 +        elf_msg(elf, "%s: %s = 0x%" PRIx64 "\n", __FUNCTION__,
   1.191 +                note_desc[type].name, val);
   1.192      }
   1.193  
   1.194 -    switch (type)
   1.195 +    switch ( type )
   1.196      {
   1.197      case XEN_ELFNOTE_LOADER:
   1.198 -	safe_strcpy(parms->loader, str);
   1.199 -	break;
   1.200 +        safe_strcpy(parms->loader, str);
   1.201 +        break;
   1.202      case XEN_ELFNOTE_GUEST_OS:
   1.203 -	safe_strcpy(parms->guest_os, str);
   1.204 -	break;
   1.205 +        safe_strcpy(parms->guest_os, str);
   1.206 +        break;
   1.207      case XEN_ELFNOTE_GUEST_VERSION:
   1.208 -	safe_strcpy(parms->guest_ver, str);
   1.209 -	break;
   1.210 +        safe_strcpy(parms->guest_ver, str);
   1.211 +        break;
   1.212      case XEN_ELFNOTE_XEN_VERSION:
   1.213 -	safe_strcpy(parms->xen_ver, str);
   1.214 -	break;
   1.215 +        safe_strcpy(parms->xen_ver, str);
   1.216 +        break;
   1.217      case XEN_ELFNOTE_PAE_MODE:
   1.218 -	if (0 == strcmp(str, "yes"))
   1.219 -	    parms->pae = 2 /* extended_cr3 */;
   1.220 -	if (strstr(str, "bimodal"))
   1.221 -	    parms->pae = 3 /* bimodal */;
   1.222 -	break;
   1.223 +        if ( !strcmp(str, "yes") )
   1.224 +            parms->pae = 2 /* extended_cr3 */;
   1.225 +        if ( strstr(str, "bimodal") )
   1.226 +            parms->pae = 3 /* bimodal */;
   1.227 +        break;
   1.228      case XEN_ELFNOTE_BSD_SYMTAB:
   1.229 -	if (0 == strcmp(str, "yes"))
   1.230 -	    parms->bsd_symtab = 1;
   1.231 -	break;
   1.232 +        if ( !strcmp(str, "yes") )
   1.233 +            parms->bsd_symtab = 1;
   1.234 +        break;
   1.235  
   1.236      case XEN_ELFNOTE_VIRT_BASE:
   1.237 -	parms->virt_base = val;
   1.238 -	break;
   1.239 +        parms->virt_base = val;
   1.240 +        break;
   1.241      case XEN_ELFNOTE_ENTRY:
   1.242 -	parms->virt_entry = val;
   1.243 -	break;
   1.244 +        parms->virt_entry = val;
   1.245 +        break;
   1.246      case XEN_ELFNOTE_PADDR_OFFSET:
   1.247 -	parms->elf_paddr_offset = val;
   1.248 -	break;
   1.249 +        parms->elf_paddr_offset = val;
   1.250 +        break;
   1.251      case XEN_ELFNOTE_HYPERCALL_PAGE:
   1.252 -	parms->virt_hypercall = val;
   1.253 -	break;
   1.254 +        parms->virt_hypercall = val;
   1.255 +        break;
   1.256      case XEN_ELFNOTE_HV_START_LOW:
   1.257 -	parms->virt_hv_start_low = val;
   1.258 -	break;
   1.259 +        parms->virt_hv_start_low = val;
   1.260 +        break;
   1.261  
   1.262      case XEN_ELFNOTE_FEATURES:
   1.263 -	if (0 != elf_xen_parse_features(str, parms->f_supported,
   1.264 -					parms->f_required))
   1.265 -	    return -1;
   1.266 -	break;
   1.267 +        if ( elf_xen_parse_features(str, parms->f_supported,
   1.268 +                                    parms->f_required) )
   1.269 +            return -1;
   1.270 +        break;
   1.271  
   1.272      }
   1.273      return 0;
   1.274 @@ -180,83 +182,85 @@ int elf_xen_parse_note(struct elf_binary
   1.275  /* __xen_guest section                                                      */
   1.276  
   1.277  int elf_xen_parse_guest_info(struct elf_binary *elf,
   1.278 -			     struct elf_dom_parms *parms)
   1.279 +                             struct elf_dom_parms *parms)
   1.280  {
   1.281      const char *h;
   1.282      char name[32], value[128];
   1.283      int len;
   1.284  
   1.285      h = parms->guest_info;
   1.286 -    while (*h)
   1.287 +    while ( *h )
   1.288      {
   1.289 -	memset(name, 0, sizeof(name));
   1.290 -	memset(value, 0, sizeof(value));
   1.291 -	for (len = 0;; len++, h++) {
   1.292 -	    if (len >= sizeof(name)-1)
   1.293 -		break;
   1.294 -	    if (*h == '\0')
   1.295 -		break;
   1.296 -	    if (*h == ',')
   1.297 -	    {
   1.298 -		h++;
   1.299 -		break;
   1.300 -	    }
   1.301 -	    if (*h == '=')
   1.302 -	    {
   1.303 -		h++;
   1.304 -		for (len = 0;; len++, h++) {
   1.305 -		    if (len >= sizeof(value)-1)
   1.306 -			break;
   1.307 -		    if (*h == '\0')
   1.308 -			break;
   1.309 -		    if (*h == ',')
   1.310 -		    {
   1.311 -			h++;
   1.312 -			break;
   1.313 -		    }
   1.314 -		    value[len] = *h;
   1.315 -		}
   1.316 -		break;
   1.317 -	    }
   1.318 -	    name[len] = *h;
   1.319 -	}
   1.320 -	elf_msg(elf, "%s: %s=\"%s\"\n", __FUNCTION__, name, value);
   1.321 +        memset(name, 0, sizeof(name));
   1.322 +        memset(value, 0, sizeof(value));
   1.323 +        for ( len = 0;; len++, h++ )
   1.324 +        {
   1.325 +            if ( len >= sizeof(name)-1 )
   1.326 +                break;
   1.327 +            if ( *h == '\0' )
   1.328 +                break;
   1.329 +            if ( *h == ',' )
   1.330 +            {
   1.331 +                h++;
   1.332 +                break;
   1.333 +            }
   1.334 +            if ( *h == '=' )
   1.335 +            {
   1.336 +                h++;
   1.337 +                for ( len = 0;; len++, h++ )
   1.338 +                {
   1.339 +                    if ( len >= sizeof(value)-1 )
   1.340 +                        break;
   1.341 +                    if ( *h == '\0' )
   1.342 +                        break;
   1.343 +                    if ( *h == ',' )
   1.344 +                    {
   1.345 +                        h++;
   1.346 +                        break;
   1.347 +                    }
   1.348 +                    value[len] = *h;
   1.349 +                }
   1.350 +                break;
   1.351 +            }
   1.352 +            name[len] = *h;
   1.353 +        }
   1.354 +        elf_msg(elf, "%s: %s=\"%s\"\n", __FUNCTION__, name, value);
   1.355  
   1.356 -	/* strings */
   1.357 -	if (0 == strcmp(name, "LOADER"))
   1.358 -	    safe_strcpy(parms->loader, value);
   1.359 -	if (0 == strcmp(name, "GUEST_OS"))
   1.360 -	    safe_strcpy(parms->guest_os, value);
   1.361 -	if (0 == strcmp(name, "GUEST_VER"))
   1.362 -	    safe_strcpy(parms->guest_ver, value);
   1.363 -	if (0 == strcmp(name, "XEN_VER"))
   1.364 -	    safe_strcpy(parms->xen_ver, value);
   1.365 -	if (0 == strcmp(name, "PAE"))
   1.366 -	{
   1.367 -	    if (0 == strcmp(value, "yes[extended-cr3]"))
   1.368 -		parms->pae = 2 /* extended_cr3 */;
   1.369 -	    else if (0 == strncmp(value, "yes", 3))
   1.370 -		parms->pae = 1 /* yes */;
   1.371 -	}
   1.372 -	if (0 == strcmp(name, "BSD_SYMTAB"))
   1.373 -	    parms->bsd_symtab = 1;
   1.374 +        /* strings */
   1.375 +        if ( !strcmp(name, "LOADER") )
   1.376 +            safe_strcpy(parms->loader, value);
   1.377 +        if ( !strcmp(name, "GUEST_OS") )
   1.378 +            safe_strcpy(parms->guest_os, value);
   1.379 +        if ( !strcmp(name, "GUEST_VER") )
   1.380 +            safe_strcpy(parms->guest_ver, value);
   1.381 +        if ( !strcmp(name, "XEN_VER") )
   1.382 +            safe_strcpy(parms->xen_ver, value);
   1.383 +        if ( !strcmp(name, "PAE") )
   1.384 +        {
   1.385 +            if ( !strcmp(value, "yes[extended-cr3]") )
   1.386 +                parms->pae = 2 /* extended_cr3 */;
   1.387 +            else if ( !strncmp(value, "yes", 3) )
   1.388 +                parms->pae = 1 /* yes */;
   1.389 +        }
   1.390 +        if ( !strcmp(name, "BSD_SYMTAB") )
   1.391 +            parms->bsd_symtab = 1;
   1.392  
   1.393 -	/* longs */
   1.394 -	if (0 == strcmp(name, "VIRT_BASE"))
   1.395 -	    parms->virt_base = strtoull(value, NULL, 0);
   1.396 -	if (0 == strcmp(name, "VIRT_ENTRY"))
   1.397 -	    parms->virt_entry = strtoull(value, NULL, 0);
   1.398 -	if (0 == strcmp(name, "ELF_PADDR_OFFSET"))
   1.399 -	    parms->elf_paddr_offset = strtoull(value, NULL, 0);
   1.400 -	if (0 == strcmp(name, "HYPERCALL_PAGE"))
   1.401 -	    parms->virt_hypercall = (strtoull(value, NULL, 0) << 12) +
   1.402 -		parms->virt_base;
   1.403 +        /* longs */
   1.404 +        if ( !strcmp(name, "VIRT_BASE") )
   1.405 +            parms->virt_base = strtoull(value, NULL, 0);
   1.406 +        if ( !strcmp(name, "VIRT_ENTRY") )
   1.407 +            parms->virt_entry = strtoull(value, NULL, 0);
   1.408 +        if ( !strcmp(name, "ELF_PADDR_OFFSET") )
   1.409 +            parms->elf_paddr_offset = strtoull(value, NULL, 0);
   1.410 +        if ( !strcmp(name, "HYPERCALL_PAGE") )
   1.411 +            parms->virt_hypercall = (strtoull(value, NULL, 0) << 12) +
   1.412 +                parms->virt_base;
   1.413  
   1.414 -	/* other */
   1.415 -	if (0 == strcmp(name, "FEATURES"))
   1.416 -	    if (0 != elf_xen_parse_features(value, parms->f_supported,
   1.417 -					    parms->f_required))
   1.418 -		return -1;
   1.419 +        /* other */
   1.420 +        if ( !strcmp(name, "FEATURES") )
   1.421 +            if ( elf_xen_parse_features(value, parms->f_supported,
   1.422 +                                        parms->f_required) )
   1.423 +                return -1;
   1.424      }
   1.425      return 0;
   1.426  }
   1.427 @@ -265,54 +269,59 @@ int elf_xen_parse_guest_info(struct elf_
   1.428  /* sanity checks                                                            */
   1.429  
   1.430  static int elf_xen_note_check(struct elf_binary *elf,
   1.431 -			      struct elf_dom_parms *parms)
   1.432 +                              struct elf_dom_parms *parms)
   1.433  {
   1.434 -    if (NULL == parms->elf_note_start && NULL == parms->guest_info) {
   1.435 -	int machine = elf_uval(elf, elf->ehdr, e_machine);
   1.436 -	if (EM_386 == machine || EM_X86_64 == machine) {
   1.437 -	    elf_err(elf, "%s: ERROR: Not a Xen-ELF image: "
   1.438 -		    "No ELF notes or '__xen_guest' section found.\n",
   1.439 -		    __FUNCTION__);
   1.440 -	    return -1;
   1.441 -	}
   1.442 -	return 0;
   1.443 +    if ( (parms->elf_note_start == NULL) && (parms->guest_info == NULL) )
   1.444 +    {
   1.445 +        int machine = elf_uval(elf, elf->ehdr, e_machine);
   1.446 +        if ( (machine == EM_386) || (machine == EM_X86_64) )
   1.447 +        {
   1.448 +            elf_err(elf, "%s: ERROR: Not a Xen-ELF image: "
   1.449 +                    "No ELF notes or '__xen_guest' section found.\n",
   1.450 +                    __FUNCTION__);
   1.451 +            return -1;
   1.452 +        }
   1.453 +        return 0;
   1.454      }
   1.455  
   1.456      /* Check the contents of the Xen notes or guest string. */
   1.457 -    if ( ( 0 == strlen(parms->loader) || strncmp(parms->loader, "generic", 7) ) &&
   1.458 -	 ( 0 == strlen(parms->guest_os) || strncmp(parms->guest_os, "linux", 5) ) )
   1.459 +    if ( ((strlen(parms->loader) == 0) ||
   1.460 +          strncmp(parms->loader, "generic", 7)) &&
   1.461 +         ((strlen(parms->guest_os) == 0) ||
   1.462 +          strncmp(parms->guest_os, "linux", 5)) )
   1.463      {
   1.464 -	elf_err(elf, "%s: ERROR: Will only load images built for the generic "
   1.465 -		"loader or Linux images", __FUNCTION__);
   1.466 -	return -1;
   1.467 +        elf_err(elf, "%s: ERROR: Will only load images built for the generic "
   1.468 +                "loader or Linux images", __FUNCTION__);
   1.469 +        return -1;
   1.470      }
   1.471  
   1.472 -    if ( 0 == strlen(parms->xen_ver) || strncmp(parms->xen_ver, "xen-3.0", 7) )
   1.473 +    if ( (strlen(parms->xen_ver) == 0) ||
   1.474 +         strncmp(parms->xen_ver, "xen-3.0", 7) )
   1.475      {
   1.476 -	elf_err(elf, "%s: ERROR: Xen will only load images built for Xen v3.0\n",
   1.477 -		__FUNCTION__);
   1.478 -	return -1;
   1.479 +        elf_err(elf, "%s: ERROR: Xen will only load images built "
   1.480 +                "for Xen v3.0\n", __FUNCTION__);
   1.481 +        return -1;
   1.482      }
   1.483      return 0;
   1.484  }
   1.485  
   1.486  static int elf_xen_addr_calc_check(struct elf_binary *elf,
   1.487 -				   struct elf_dom_parms *parms)
   1.488 +                                   struct elf_dom_parms *parms)
   1.489  {
   1.490 -    if (UNSET_ADDR != parms->elf_paddr_offset &&
   1.491 -	UNSET_ADDR == parms->virt_base )
   1.492 +    if ( (parms->elf_paddr_offset != UNSET_ADDR) &&
   1.493 +         (parms->virt_base == UNSET_ADDR) )
   1.494      {
   1.495 -	elf_err(elf, "%s: ERROR: ELF_PADDR_OFFSET set, VIRT_BASE unset\n",
   1.496 -		__FUNCTION__);
   1.497 +        elf_err(elf, "%s: ERROR: ELF_PADDR_OFFSET set, VIRT_BASE unset\n",
   1.498 +                __FUNCTION__);
   1.499          return -1;
   1.500      }
   1.501  
   1.502      /* Initial guess for virt_base is 0 if it is not explicitly defined. */
   1.503 -    if (UNSET_ADDR == parms->virt_base)
   1.504 +    if ( parms->virt_base == UNSET_ADDR )
   1.505      {
   1.506 -	parms->virt_base = 0;
   1.507 -	elf_msg(elf, "%s: VIRT_BASE unset, using 0x%" PRIx64 "\n",
   1.508 -		__FUNCTION__, parms->virt_base);
   1.509 +        parms->virt_base = 0;
   1.510 +        elf_msg(elf, "%s: VIRT_BASE unset, using 0x%" PRIx64 "\n",
   1.511 +                __FUNCTION__, parms->virt_base);
   1.512      }
   1.513  
   1.514      /*
   1.515 @@ -324,22 +333,22 @@ static int elf_xen_addr_calc_check(struc
   1.516       * If we are using the modern ELF notes interface then the default
   1.517       * is 0.
   1.518       */
   1.519 -    if (UNSET_ADDR == parms->elf_paddr_offset)
   1.520 +    if ( parms->elf_paddr_offset == UNSET_ADDR )
   1.521      {
   1.522 -	if (parms->elf_note_start)
   1.523 -	    parms->elf_paddr_offset = 0;
   1.524 -	else
   1.525 -	    parms->elf_paddr_offset = parms->virt_base;
   1.526 -	elf_msg(elf, "%s: ELF_PADDR_OFFSET unset, using 0x%" PRIx64 "\n",
   1.527 -		__FUNCTION__, parms->elf_paddr_offset);
   1.528 +        if ( parms->elf_note_start )
   1.529 +            parms->elf_paddr_offset = 0;
   1.530 +        else
   1.531 +            parms->elf_paddr_offset = parms->virt_base;
   1.532 +        elf_msg(elf, "%s: ELF_PADDR_OFFSET unset, using 0x%" PRIx64 "\n",
   1.533 +                __FUNCTION__, parms->elf_paddr_offset);
   1.534      }
   1.535  
   1.536      parms->virt_offset = parms->virt_base - parms->elf_paddr_offset;
   1.537      parms->virt_kstart = elf->pstart + parms->virt_offset;
   1.538      parms->virt_kend   = elf->pend   + parms->virt_offset;
   1.539  
   1.540 -    if (UNSET_ADDR == parms->virt_entry)
   1.541 -	parms->virt_entry = elf_uval(elf, elf->ehdr, e_entry);
   1.542 +    if ( parms->virt_entry == UNSET_ADDR )
   1.543 +        parms->virt_entry = elf_uval(elf, elf->ehdr, e_entry);
   1.544  
   1.545      elf_msg(elf, "%s: addresses:\n", __FUNCTION__);
   1.546      elf_msg(elf, "    virt_base        = 0x%" PRIx64 "\n", parms->virt_base);
   1.547 @@ -355,7 +364,7 @@ static int elf_xen_addr_calc_check(struc
   1.548           (parms->virt_base > parms->virt_kstart) )
   1.549      {
   1.550          elf_err(elf, "%s: ERROR: ELF start or entries are out of bounds.\n",
   1.551 -		__FUNCTION__);
   1.552 +                __FUNCTION__);
   1.553          return -1;
   1.554      }
   1.555  
   1.556 @@ -366,7 +375,7 @@ static int elf_xen_addr_calc_check(struc
   1.557  /* glue it all together ...                                                 */
   1.558  
   1.559  int elf_xen_parse(struct elf_binary *elf,
   1.560 -		  struct elf_dom_parms *parms)
   1.561 +                  struct elf_dom_parms *parms)
   1.562  {
   1.563      const elf_note *note;
   1.564      const elf_shdr *shdr;
   1.565 @@ -382,39 +391,49 @@ int elf_xen_parse(struct elf_binary *elf
   1.566  
   1.567      /* find and parse elf notes */
   1.568      count = elf_shdr_count(elf);
   1.569 -    for (i = 0; i < count; i++)
   1.570 +    for ( i = 0; i < count; i++ )
   1.571      {
   1.572 -	shdr = elf_shdr_by_index(elf, i);
   1.573 -	if (0 == strcmp(elf_section_name(elf, shdr), "__xen_guest"))
   1.574 -	    parms->guest_info = elf_section_start(elf, shdr);
   1.575 -	if (elf_uval(elf, shdr, sh_type) != SHT_NOTE)
   1.576 -	    continue;
   1.577 -	parms->elf_note_start = elf_section_start(elf, shdr);
   1.578 -	parms->elf_note_end   = elf_section_end(elf, shdr);
   1.579 -	for (note = parms->elf_note_start;
   1.580 -	     (void *)note < parms->elf_note_end;
   1.581 -	     note = elf_note_next(elf, note))
   1.582 -	{
   1.583 -	    if (0 != strcmp(elf_note_name(elf, note), "Xen"))
   1.584 -		continue;
   1.585 -	    if (0 != elf_xen_parse_note(elf, parms, note))
   1.586 -		return -1;
   1.587 -	    xen_elfnotes++;
   1.588 -	}
   1.589 +        shdr = elf_shdr_by_index(elf, i);
   1.590 +        if ( !strcmp(elf_section_name(elf, shdr), "__xen_guest") )
   1.591 +            parms->guest_info = elf_section_start(elf, shdr);
   1.592 +        if ( elf_uval(elf, shdr, sh_type) != SHT_NOTE )
   1.593 +            continue;
   1.594 +        parms->elf_note_start = elf_section_start(elf, shdr);
   1.595 +        parms->elf_note_end   = elf_section_end(elf, shdr);
   1.596 +        for ( note = parms->elf_note_start;
   1.597 +              (void *)note < parms->elf_note_end;
   1.598 +              note = elf_note_next(elf, note) )
   1.599 +        {
   1.600 +            if ( strcmp(elf_note_name(elf, note), "Xen") )
   1.601 +                continue;
   1.602 +            if ( elf_xen_parse_note(elf, parms, note) )
   1.603 +                return -1;
   1.604 +            xen_elfnotes++;
   1.605 +        }
   1.606      }
   1.607  
   1.608 -    if (!xen_elfnotes && parms->guest_info)
   1.609 +    if ( !xen_elfnotes && parms->guest_info )
   1.610      {
   1.611 -	parms->elf_note_start = NULL;
   1.612 -	parms->elf_note_end   = NULL;
   1.613 -	elf_msg(elf, "%s: __xen_guest: \"%s\"\n", __FUNCTION__,
   1.614 -		parms->guest_info);
   1.615 -	elf_xen_parse_guest_info(elf, parms);
   1.616 +        parms->elf_note_start = NULL;
   1.617 +        parms->elf_note_end   = NULL;
   1.618 +        elf_msg(elf, "%s: __xen_guest: \"%s\"\n", __FUNCTION__,
   1.619 +                parms->guest_info);
   1.620 +        elf_xen_parse_guest_info(elf, parms);
   1.621      }
   1.622  
   1.623 -    if (0 != elf_xen_note_check(elf, parms))
   1.624 -	return -1;
   1.625 -    if (0 != elf_xen_addr_calc_check(elf, parms))
   1.626 -	return -1;
   1.627 +    if ( elf_xen_note_check(elf, parms) != 0 )
   1.628 +        return -1;
   1.629 +    if ( elf_xen_addr_calc_check(elf, parms) != 0 )
   1.630 +        return -1;
   1.631      return 0;
   1.632  }
   1.633 +
   1.634 +/*
   1.635 + * Local variables:
   1.636 + * mode: C
   1.637 + * c-set-style: "BSD"
   1.638 + * c-basic-offset: 4
   1.639 + * tab-width: 4
   1.640 + * indent-tabs-mode: nil
   1.641 + * End:
   1.642 + */
     2.1 --- a/xen/common/libelf/libelf-loader.c	Wed Feb 14 16:05:28 2007 +0000
     2.2 +++ b/xen/common/libelf/libelf-loader.c	Wed Feb 14 16:06:10 2007 +0000
     2.3 @@ -11,10 +11,10 @@ int elf_init(struct elf_binary *elf, con
     2.4      const elf_shdr *shdr;
     2.5      uint64_t i, count, section, offset;
     2.6  
     2.7 -    if (!elf_is_elfbinary(image))
     2.8 +    if ( !elf_is_elfbinary(image) )
     2.9      {
    2.10 -	elf_err(elf, "%s: not an ELF binary\n", __FUNCTION__);
    2.11 -	return -1;
    2.12 +        elf_err(elf, "%s: not an ELF binary\n", __FUNCTION__);
    2.13 +        return -1;
    2.14      }
    2.15  
    2.16      memset(elf, 0, sizeof(*elf));
    2.17 @@ -26,46 +26,46 @@ int elf_init(struct elf_binary *elf, con
    2.18  
    2.19      /* sanity check phdr */
    2.20      offset = elf_uval(elf, elf->ehdr, e_phoff) +
    2.21 -	elf_uval(elf, elf->ehdr, e_phentsize) * elf_phdr_count(elf);
    2.22 -    if (offset > elf->size)
    2.23 +        elf_uval(elf, elf->ehdr, e_phentsize) * elf_phdr_count(elf);
    2.24 +    if ( offset > elf->size )
    2.25      {
    2.26 -	elf_err(elf, "%s: phdr overflow (off %" PRIx64 " > size %lx)\n",
    2.27 -		__FUNCTION__, offset, (unsigned long)elf->size);
    2.28 -	return -1;
    2.29 +        elf_err(elf, "%s: phdr overflow (off %" PRIx64 " > size %lx)\n",
    2.30 +                __FUNCTION__, offset, (unsigned long)elf->size);
    2.31 +        return -1;
    2.32      }
    2.33  
    2.34      /* sanity check shdr */
    2.35      offset = elf_uval(elf, elf->ehdr, e_shoff) +
    2.36 -	elf_uval(elf, elf->ehdr, e_shentsize) * elf_shdr_count(elf);
    2.37 -    if (offset > elf->size)
    2.38 +        elf_uval(elf, elf->ehdr, e_shentsize) * elf_shdr_count(elf);
    2.39 +    if ( offset > elf->size )
    2.40      {
    2.41 -	elf_err(elf, "%s: shdr overflow (off %" PRIx64 " > size %lx)\n",
    2.42 -		__FUNCTION__, offset, (unsigned long)elf->size);
    2.43 -	return -1;
    2.44 +        elf_err(elf, "%s: shdr overflow (off %" PRIx64 " > size %lx)\n",
    2.45 +                __FUNCTION__, offset, (unsigned long)elf->size);
    2.46 +        return -1;
    2.47      }
    2.48  
    2.49      /* find section string table */
    2.50      section = elf_uval(elf, elf->ehdr, e_shstrndx);
    2.51      shdr = elf_shdr_by_index(elf, section);
    2.52 -    if (NULL != shdr)
    2.53 -	elf->sec_strtab = elf_section_start(elf, shdr);
    2.54 +    if ( shdr != NULL )
    2.55 +        elf->sec_strtab = elf_section_start(elf, shdr);
    2.56  
    2.57      /* find symbol table, symbol string table */
    2.58      count = elf_shdr_count(elf);
    2.59 -    for (i = 0; i < count; i++)
    2.60 +    for ( i = 0; i < count; i++ )
    2.61      {
    2.62 -	shdr = elf_shdr_by_index(elf, i);
    2.63 -	if (elf_uval(elf, shdr, sh_type) != SHT_SYMTAB)
    2.64 -	    continue;
    2.65 -	elf->sym_tab = shdr;
    2.66 -	shdr = elf_shdr_by_index(elf, elf_uval(elf, shdr, sh_link));
    2.67 -	if (NULL == shdr)
    2.68 -	{
    2.69 -	    elf->sym_tab = NULL;
    2.70 -	    continue;
    2.71 -	}
    2.72 -	elf->sym_strtab = elf_section_start(elf, shdr);
    2.73 -	break;
    2.74 +        shdr = elf_shdr_by_index(elf, i);
    2.75 +        if ( elf_uval(elf, shdr, sh_type) != SHT_SYMTAB )
    2.76 +            continue;
    2.77 +        elf->sym_tab = shdr;
    2.78 +        shdr = elf_shdr_by_index(elf, elf_uval(elf, shdr, sh_link));
    2.79 +        if ( shdr == NULL )
    2.80 +        {
    2.81 +            elf->sym_tab = NULL;
    2.82 +            continue;
    2.83 +        }
    2.84 +        elf->sym_strtab = elf_section_start(elf, shdr);
    2.85 +        break;
    2.86      }
    2.87      return 0;
    2.88  }
    2.89 @@ -91,24 +91,24 @@ void elf_parse_binary(struct elf_binary 
    2.90      uint64_t i, count, paddr, memsz;
    2.91  
    2.92      count = elf_uval(elf, elf->ehdr, e_phnum);
    2.93 -    for (i = 0; i < count; i++)
    2.94 +    for ( i = 0; i < count; i++ )
    2.95      {
    2.96 -	phdr = elf_phdr_by_index(elf, i);
    2.97 -	if (!elf_phdr_is_loadable(elf, phdr))
    2.98 -	    continue;
    2.99 -	paddr = elf_uval(elf, phdr, p_paddr);
   2.100 -	memsz = elf_uval(elf, phdr, p_memsz);
   2.101 -	elf_msg(elf, "%s: phdr: paddr=0x%" PRIx64
   2.102 -		" memsz=0x%" PRIx64 "\n", __FUNCTION__, paddr, memsz);
   2.103 -	if (low > paddr)
   2.104 -	    low = paddr;
   2.105 -	if (high < paddr + memsz)
   2.106 -	    high = paddr + memsz;
   2.107 +        phdr = elf_phdr_by_index(elf, i);
   2.108 +        if ( !elf_phdr_is_loadable(elf, phdr) )
   2.109 +            continue;
   2.110 +        paddr = elf_uval(elf, phdr, p_paddr);
   2.111 +        memsz = elf_uval(elf, phdr, p_memsz);
   2.112 +        elf_msg(elf, "%s: phdr: paddr=0x%" PRIx64
   2.113 +                " memsz=0x%" PRIx64 "\n", __FUNCTION__, paddr, memsz);
   2.114 +        if ( low > paddr )
   2.115 +            low = paddr;
   2.116 +        if ( high < paddr + memsz )
   2.117 +            high = paddr + memsz;
   2.118      }
   2.119      elf->pstart = low;
   2.120      elf->pend = high;
   2.121      elf_msg(elf, "%s: memory: 0x%" PRIx64 " -> 0x%" PRIx64 "\n",
   2.122 -	    __FUNCTION__, elf->pstart, elf->pend);
   2.123 +            __FUNCTION__, elf->pstart, elf->pend);
   2.124  }
   2.125  
   2.126  void elf_load_binary(struct elf_binary *elf)
   2.127 @@ -118,18 +118,18 @@ void elf_load_binary(struct elf_binary *
   2.128      char *dest;
   2.129  
   2.130      count = elf_uval(elf, elf->ehdr, e_phnum);
   2.131 -    for (i = 0; i < count; i++)
   2.132 +    for ( i = 0; i < count; i++ )
   2.133      {
   2.134 -	phdr = elf_phdr_by_index(elf, i);
   2.135 -	if (!elf_phdr_is_loadable(elf, phdr))
   2.136 -	    continue;
   2.137 -	paddr = elf_uval(elf, phdr, p_paddr);
   2.138 -	offset = elf_uval(elf, phdr, p_offset);
   2.139 -	filesz = elf_uval(elf, phdr, p_filesz);
   2.140 -	memsz = elf_uval(elf, phdr, p_memsz);
   2.141 -	dest = elf_get_ptr(elf, paddr);
   2.142 -	memcpy(dest, elf->image + offset, filesz);
   2.143 -	memset(dest + filesz, 0, memsz - filesz);
   2.144 +        phdr = elf_phdr_by_index(elf, i);
   2.145 +        if ( !elf_phdr_is_loadable(elf, phdr) )
   2.146 +            continue;
   2.147 +        paddr = elf_uval(elf, phdr, p_paddr);
   2.148 +        offset = elf_uval(elf, phdr, p_offset);
   2.149 +        filesz = elf_uval(elf, phdr, p_filesz);
   2.150 +        memsz = elf_uval(elf, phdr, p_memsz);
   2.151 +        dest = elf_get_ptr(elf, paddr);
   2.152 +        memcpy(dest, elf->image + offset, filesz);
   2.153 +        memset(dest + filesz, 0, memsz - filesz);
   2.154      }
   2.155  }
   2.156  
   2.157 @@ -144,13 +144,24 @@ uint64_t elf_lookup_addr(struct elf_bina
   2.158      uint64_t value;
   2.159  
   2.160      sym = elf_sym_by_name(elf, symbol);
   2.161 -    if (NULL == sym)
   2.162 +    if ( sym == NULL )
   2.163      {
   2.164 -	elf_err(elf, "%s: not found: %s\n", __FUNCTION__, symbol);
   2.165 -	return -1;
   2.166 +        elf_err(elf, "%s: not found: %s\n", __FUNCTION__, symbol);
   2.167 +        return -1;
   2.168      }
   2.169 +
   2.170      value = elf_uval(elf, sym, st_value);
   2.171      elf_msg(elf, "%s: symbol \"%s\" at 0x%" PRIx64 "\n", __FUNCTION__,
   2.172 -	    symbol, value);
   2.173 +            symbol, value);
   2.174      return value;
   2.175  }
   2.176 +
   2.177 +/*
   2.178 + * Local variables:
   2.179 + * mode: C
   2.180 + * c-set-style: "BSD"
   2.181 + * c-basic-offset: 4
   2.182 + * tab-width: 4
   2.183 + * indent-tabs-mode: nil
   2.184 + * End:
   2.185 + */
     3.1 --- a/xen/common/libelf/libelf-private.h	Wed Feb 14 16:05:28 2007 +0000
     3.2 +++ b/xen/common/libelf/libelf-private.h	Wed Feb 14 16:06:10 2007 +0000
     3.3 @@ -12,9 +12,9 @@
     3.4  #include <public/libelf.h>
     3.5  
     3.6  #define elf_msg(elf, fmt, args ... ) \
     3.7 -	if (elf->verbose) printk(fmt, ## args )
     3.8 +   if (elf->verbose) printk(fmt, ## args )
     3.9  #define elf_err(elf, fmt, args ... ) \
    3.10 -	printk(fmt, ## args )
    3.11 +   printk(fmt, ## args )
    3.12  
    3.13  #define strtoull(str, end, base) simple_strtoull(str, end, base)
    3.14  #define bswap_16(x) swab16(x)
    3.15 @@ -43,12 +43,12 @@
    3.16  #include "xc_private.h"
    3.17  
    3.18  #define elf_msg(elf, fmt, args ... ) \
    3.19 -	if (elf->log && elf->verbose) fprintf(elf->log, fmt , ## args )
    3.20 -#define elf_err(elf, fmt, args ... ) do {                 \
    3.21 -	if (elf->log)                                     \
    3.22 -            fprintf(elf->log, fmt , ## args );            \
    3.23 -        xc_set_error(XC_INVALID_KERNEL, fmt , ## args );  \
    3.24 -	} while (0)
    3.25 +    if (elf->log && elf->verbose) fprintf(elf->log, fmt , ## args )
    3.26 +#define elf_err(elf, fmt, args ... ) do {               \
    3.27 +    if (elf->log)                                       \
    3.28 +        fprintf(elf->log, fmt , ## args );              \
    3.29 +    xc_set_error(XC_INVALID_KERNEL, fmt , ## args );    \
    3.30 +} while (0)
    3.31  
    3.32  #define safe_strcpy(d,s)                        \
    3.33  do { strncpy((d),(s),sizeof((d))-1);            \
    3.34 @@ -58,3 +58,13 @@ do { strncpy((d),(s),sizeof((d))-1);    
    3.35  #endif
    3.36  
    3.37  #endif /* __LIBELF_PRIVATE_H_ */
    3.38 +
    3.39 +/*
    3.40 + * Local variables:
    3.41 + * mode: C
    3.42 + * c-set-style: "BSD"
    3.43 + * c-basic-offset: 4
    3.44 + * tab-width: 4
    3.45 + * indent-tabs-mode: nil
    3.46 + * End:
    3.47 + */
     4.1 --- a/xen/common/libelf/libelf-relocate.c	Wed Feb 14 16:05:28 2007 +0000
     4.2 +++ b/xen/common/libelf/libelf-relocate.c	Wed Feb 14 16:06:10 2007 +0000
     4.3 @@ -46,22 +46,22 @@ static const char *rel_names_i386[] = {
     4.4  };
     4.5  
     4.6  static int elf_reloc_i386(struct elf_binary *elf, int type,
     4.7 -			  uint64_t addr, uint64_t value)
     4.8 +                          uint64_t addr, uint64_t value)
     4.9  {
    4.10      void *ptr = elf_get_ptr(elf, addr);
    4.11      uint32_t *u32;
    4.12  
    4.13 -    switch (type)
    4.14 +    switch ( type )
    4.15      {
    4.16      case 1 /* R_386_32 */ :
    4.17 -	u32 = ptr;
    4.18 -	*u32 += elf->reloc_offset;
    4.19 -	break;
    4.20 +        u32 = ptr;
    4.21 +        *u32 += elf->reloc_offset;
    4.22 +        break;
    4.23      case 2 /* R_386_PC32 */ :
    4.24 -	/* nothing */
    4.25 -	break;
    4.26 +        /* nothing */
    4.27 +        break;
    4.28      default:
    4.29 -	return -1;
    4.30 +        return -1;
    4.31      }
    4.32      return 0;
    4.33  }
    4.34 @@ -96,54 +96,57 @@ static const char *rel_names_x86_64[] = 
    4.35  };
    4.36  
    4.37  static int elf_reloc_x86_64(struct elf_binary *elf, int type,
    4.38 -			    uint64_t addr, uint64_t value)
    4.39 +                            uint64_t addr, uint64_t value)
    4.40  {
    4.41      void *ptr = elf_get_ptr(elf, addr);
    4.42      uint64_t *u64;
    4.43      uint32_t *u32;
    4.44      int32_t *s32;
    4.45  
    4.46 -    switch (type)
    4.47 +    switch ( type )
    4.48      {
    4.49      case 1 /* R_X86_64_64 */ :
    4.50 -	u64 = ptr;
    4.51 -	value += elf->reloc_offset;
    4.52 -	*u64 = value;
    4.53 -	break;
    4.54 +        u64 = ptr;
    4.55 +        value += elf->reloc_offset;
    4.56 +        *u64 = value;
    4.57 +        break;
    4.58      case 2 /* R_X86_64_PC32 */ :
    4.59 -	u32 = ptr;
    4.60 -	*u32 = value - addr;
    4.61 -	if (*u32 != (uint32_t) (value - addr))
    4.62 -	{
    4.63 -	    elf_err(elf, "R_X86_64_PC32 overflow: 0x%" PRIx32 " != 0x%" PRIx32 "\n",
    4.64 -		    *u32, (uint32_t) (value - addr));
    4.65 -	    return -1;
    4.66 -	}
    4.67 -	break;
    4.68 +        u32 = ptr;
    4.69 +        *u32 = value - addr;
    4.70 +        if ( *u32 != (uint32_t)(value - addr) )
    4.71 +        {
    4.72 +            elf_err(elf, "R_X86_64_PC32 overflow: 0x%" PRIx32
    4.73 +                    " != 0x%" PRIx32 "\n",
    4.74 +                    *u32, (uint32_t) (value - addr));
    4.75 +            return -1;
    4.76 +        }
    4.77 +        break;
    4.78      case 10 /* R_X86_64_32 */ :
    4.79 -	u32 = ptr;
    4.80 -	value += elf->reloc_offset;
    4.81 -	*u32 = value;
    4.82 -	if (*u32 != value)
    4.83 -	{
    4.84 -	    elf_err(elf, "R_X86_64_32 overflow: 0x%" PRIx32 " != 0x%" PRIx64 "\n",
    4.85 -		    *u32, value);
    4.86 -	    return -1;
    4.87 -	}
    4.88 -	break;
    4.89 +        u32 = ptr;
    4.90 +        value += elf->reloc_offset;
    4.91 +        *u32 = value;
    4.92 +        if ( *u32 != value )
    4.93 +        {
    4.94 +            elf_err(elf, "R_X86_64_32 overflow: 0x%" PRIx32
    4.95 +                    " != 0x%" PRIx64 "\n",
    4.96 +                    *u32, value);
    4.97 +            return -1;
    4.98 +        }
    4.99 +        break;
   4.100      case 11 /* R_X86_64_32S */ :
   4.101 -	s32 = ptr;
   4.102 -	value += elf->reloc_offset;
   4.103 -	*s32 = value;
   4.104 -	if (*s32 != (int64_t) value)
   4.105 -	{
   4.106 -	    elf_err(elf, "R_X86_64_32S overflow: 0x%" PRIx32 " != 0x%" PRIx64 "\n",
   4.107 -		    *s32, (int64_t) value);
   4.108 -	    return -1;
   4.109 -	}
   4.110 -	break;
   4.111 +        s32 = ptr;
   4.112 +        value += elf->reloc_offset;
   4.113 +        *s32 = value;
   4.114 +        if ( *s32 != (int64_t) value )
   4.115 +        {
   4.116 +            elf_err(elf, "R_X86_64_32S overflow: 0x%" PRIx32
   4.117 +                    " != 0x%" PRIx64 "\n",
   4.118 +                    *s32, (int64_t) value);
   4.119 +            return -1;
   4.120 +        }
   4.121 +        break;
   4.122      default:
   4.123 -	return -1;
   4.124 +        return -1;
   4.125      }
   4.126      return 0;
   4.127  }
   4.128 @@ -154,19 +157,19 @@ static struct relocs {
   4.129      const char **names;
   4.130      int count;
   4.131      int (*func) (struct elf_binary * elf, int type, uint64_t addr,
   4.132 -		 uint64_t value);
   4.133 +                 uint64_t value);
   4.134  } relocs[] =
   4.135  /* *INDENT-OFF* */
   4.136  {
   4.137      [EM_386] = {
   4.138 -	.names = rel_names_i386,
   4.139 -	.count = sizeof(rel_names_i386) / sizeof(rel_names_i386[0]),
   4.140 -	.func = elf_reloc_i386,
   4.141 +        .names = rel_names_i386,
   4.142 +        .count = sizeof(rel_names_i386) / sizeof(rel_names_i386[0]),
   4.143 +        .func = elf_reloc_i386,
   4.144      },
   4.145      [EM_X86_64] = {
   4.146 -	.names = rel_names_x86_64,
   4.147 -	.count = sizeof(rel_names_x86_64) / sizeof(rel_names_x86_64[0]),
   4.148 -	.func = elf_reloc_x86_64,
   4.149 +        .names = rel_names_x86_64,
   4.150 +        .count = sizeof(rel_names_x86_64) / sizeof(rel_names_x86_64[0]),
   4.151 +        .func = elf_reloc_x86_64,
   4.152      }
   4.153  };
   4.154  /* *INDENT-ON* */
   4.155 @@ -175,18 +178,18 @@ static struct relocs {
   4.156  
   4.157  static const char *rela_name(int machine, int type)
   4.158  {
   4.159 -    if (machine > sizeof(relocs) / sizeof(relocs[0]))
   4.160 -	return "unknown mach";
   4.161 -    if (!relocs[machine].names)
   4.162 -	return "unknown mach";
   4.163 -    if (type > relocs[machine].count)
   4.164 -	return "unknown rela";
   4.165 +    if ( machine > sizeof(relocs) / sizeof(relocs[0]) )
   4.166 +        return "unknown mach";
   4.167 +    if ( !relocs[machine].names )
   4.168 +        return "unknown mach";
   4.169 +    if ( type > relocs[machine].count )
   4.170 +        return "unknown rela";
   4.171      return relocs[machine].names[type];
   4.172  }
   4.173  
   4.174  static int elf_reloc_section(struct elf_binary *elf,
   4.175 -			     const elf_shdr * rels,
   4.176 -			     const elf_shdr * sect, const elf_shdr * syms)
   4.177 +                             const elf_shdr * rels,
   4.178 +                             const elf_shdr * sect, const elf_shdr * syms)
   4.179  {
   4.180      const void *ptr, *end;
   4.181      const elf_shdr *shdr;
   4.182 @@ -204,18 +207,18 @@ static int elf_reloc_section(struct elf_
   4.183      int machine;
   4.184  
   4.185      machine = elf_uval(elf, elf->ehdr, e_machine);
   4.186 -    if (machine >= sizeof(relocs) / sizeof(relocs[0]) ||
   4.187 -	NULL == relocs[machine].func)
   4.188 +    if ( (machine >= (sizeof(relocs) / sizeof(relocs[0]))) ||
   4.189 +         (relocs[machine].func == NULL) )
   4.190      {
   4.191 -	elf_err(elf, "%s: can't handle machine %d\n",
   4.192 -		__FUNCTION__, machine);
   4.193 -	return -1;
   4.194 +        elf_err(elf, "%s: can't handle machine %d\n",
   4.195 +                __FUNCTION__, machine);
   4.196 +        return -1;
   4.197      }
   4.198 -    if (elf_swap(elf))
   4.199 +    if ( elf_swap(elf) )
   4.200      {
   4.201 -	elf_err(elf, "%s: non-native byte order, relocation not supported\n",
   4.202 -		__FUNCTION__);
   4.203 -	return -1;
   4.204 +        elf_err(elf, "%s: non-native byte order, relocation not supported\n",
   4.205 +                __FUNCTION__);
   4.206 +        return -1;
   4.207      }
   4.208  
   4.209      s_type = elf_uval(elf, rels, sh_type);
   4.210 @@ -223,89 +226,89 @@ static int elf_reloc_section(struct elf_
   4.211      ptr = elf_section_start(elf, rels);
   4.212      end = elf_section_end(elf, rels);
   4.213  
   4.214 -    for (; ptr < end; ptr += rsize)
   4.215 +    for ( ; ptr < end; ptr += rsize )
   4.216      {
   4.217 -	switch (s_type)
   4.218 -	{
   4.219 -	case SHT_REL:
   4.220 -	    rel = ptr;
   4.221 -	    r_offset = elf_uval(elf, rel, r_offset);
   4.222 -	    r_info = elf_uval(elf, rel, r_info);
   4.223 -	    r_addend = 0;
   4.224 -	    break;
   4.225 -	case SHT_RELA:
   4.226 -	    rela = ptr;
   4.227 -	    r_offset = elf_uval(elf, rela, r_offset);
   4.228 -	    r_info = elf_uval(elf, rela, r_info);
   4.229 -	    r_addend = elf_uval(elf, rela, r_addend);
   4.230 -	    break;
   4.231 -	default:
   4.232 -	    /* can't happen */
   4.233 -	    return -1;
   4.234 -	}
   4.235 -	if (elf_64bit(elf))
   4.236 -	{
   4.237 -	    r_type = ELF64_R_TYPE(r_info);
   4.238 -	    r_sym = ELF64_R_SYM(r_info);
   4.239 -	}
   4.240 -	else
   4.241 -	{
   4.242 -	    r_type = ELF32_R_TYPE(r_info);
   4.243 -	    r_sym = ELF32_R_SYM(r_info);
   4.244 -	}
   4.245 +        switch ( s_type )
   4.246 +        {
   4.247 +        case SHT_REL:
   4.248 +            rel = ptr;
   4.249 +            r_offset = elf_uval(elf, rel, r_offset);
   4.250 +            r_info = elf_uval(elf, rel, r_info);
   4.251 +            r_addend = 0;
   4.252 +            break;
   4.253 +        case SHT_RELA:
   4.254 +            rela = ptr;
   4.255 +            r_offset = elf_uval(elf, rela, r_offset);
   4.256 +            r_info = elf_uval(elf, rela, r_info);
   4.257 +            r_addend = elf_uval(elf, rela, r_addend);
   4.258 +            break;
   4.259 +        default:
   4.260 +            /* can't happen */
   4.261 +            return -1;
   4.262 +        }
   4.263 +        if ( elf_64bit(elf) )
   4.264 +        {
   4.265 +            r_type = ELF64_R_TYPE(r_info);
   4.266 +            r_sym = ELF64_R_SYM(r_info);
   4.267 +        }
   4.268 +        else
   4.269 +        {
   4.270 +            r_type = ELF32_R_TYPE(r_info);
   4.271 +            r_sym = ELF32_R_SYM(r_info);
   4.272 +        }
   4.273  
   4.274 -	sym = elf_sym_by_index(elf, r_sym);
   4.275 -	shndx = elf_uval(elf, sym, st_shndx);
   4.276 -	switch (shndx)
   4.277 -	{
   4.278 -	case SHN_UNDEF:
   4.279 -	    sname = "*UNDEF*";
   4.280 -	    sbase = 0;
   4.281 -	    break;
   4.282 -	case SHN_COMMON:
   4.283 -	    elf_err(elf, "%s: invalid section: %" PRId64 "\n",
   4.284 -		    __FUNCTION__, shndx);
   4.285 -	    return -1;
   4.286 -	case SHN_ABS:
   4.287 -	    sname = "*ABS*";
   4.288 -	    sbase = 0;
   4.289 -	    break;
   4.290 -	default:
   4.291 -	    shdr = elf_shdr_by_index(elf, shndx);
   4.292 -	    if (NULL == shdr)
   4.293 -	    {
   4.294 -		elf_err(elf, "%s: invalid section: %" PRId64 "\n",
   4.295 -			__FUNCTION__, shndx);
   4.296 -		return -1;
   4.297 -	    }
   4.298 -	    sname = elf_section_name(elf, shdr);
   4.299 -	    sbase = elf_uval(elf, shdr, sh_addr);
   4.300 -	}
   4.301 +        sym = elf_sym_by_index(elf, r_sym);
   4.302 +        shndx = elf_uval(elf, sym, st_shndx);
   4.303 +        switch ( shndx )
   4.304 +        {
   4.305 +        case SHN_UNDEF:
   4.306 +            sname = "*UNDEF*";
   4.307 +            sbase = 0;
   4.308 +            break;
   4.309 +        case SHN_COMMON:
   4.310 +            elf_err(elf, "%s: invalid section: %" PRId64 "\n",
   4.311 +                    __FUNCTION__, shndx);
   4.312 +            return -1;
   4.313 +        case SHN_ABS:
   4.314 +            sname = "*ABS*";
   4.315 +            sbase = 0;
   4.316 +            break;
   4.317 +        default:
   4.318 +            shdr = elf_shdr_by_index(elf, shndx);
   4.319 +            if ( shdr == NULL )
   4.320 +            {
   4.321 +                elf_err(elf, "%s: invalid section: %" PRId64 "\n",
   4.322 +                        __FUNCTION__, shndx);
   4.323 +                return -1;
   4.324 +            }
   4.325 +            sname = elf_section_name(elf, shdr);
   4.326 +            sbase = elf_uval(elf, shdr, sh_addr);
   4.327 +        }
   4.328  
   4.329 -	addr = r_offset;
   4.330 -	value = elf_uval(elf, sym, st_value);
   4.331 -	value += r_addend;
   4.332 -
   4.333 -	if (elf->log && elf->verbose > 1)
   4.334 -	{
   4.335 -	    uint64_t st_name = elf_uval(elf, sym, st_name);
   4.336 -	    const char *name = st_name ? elf->sym_strtab + st_name : "*NONE*";
   4.337 +        addr = r_offset;
   4.338 +        value = elf_uval(elf, sym, st_value);
   4.339 +        value += r_addend;
   4.340  
   4.341 -	    elf_msg(elf,
   4.342 -		    "%s: type %s [%d], off 0x%" PRIx64 ", add 0x%" PRIx64 ","
   4.343 -		    " sym %s [0x%" PRIx64 "], sec %s [0x%" PRIx64 "]"
   4.344 -		    "  ->  addr 0x%" PRIx64 " value 0x%" PRIx64 "\n",
   4.345 -		    __FUNCTION__, rela_name(machine, r_type), r_type, r_offset,
   4.346 -		    r_addend, name, elf_uval(elf, sym, st_value), sname, sbase,
   4.347 -		    addr, value);
   4.348 -	}
   4.349 +        if ( elf->log && (elf->verbose > 1) )
   4.350 +        {
   4.351 +            uint64_t st_name = elf_uval(elf, sym, st_name);
   4.352 +            const char *name = st_name ? elf->sym_strtab + st_name : "*NONE*";
   4.353  
   4.354 -	if (-1 == relocs[machine].func(elf, r_type, addr, value))
   4.355 -	{
   4.356 -	    elf_err(elf, "%s: unknown/unsupported reloc type %s [%d]\n",
   4.357 -		    __FUNCTION__, rela_name(machine, r_type), r_type);
   4.358 -	    return -1;
   4.359 -	}
   4.360 +            elf_msg(elf,
   4.361 +                    "%s: type %s [%d], off 0x%" PRIx64 ", add 0x%" PRIx64 ","
   4.362 +                    " sym %s [0x%" PRIx64 "], sec %s [0x%" PRIx64 "]"
   4.363 +                    "  ->  addr 0x%" PRIx64 " value 0x%" PRIx64 "\n",
   4.364 +                    __FUNCTION__, rela_name(machine, r_type), r_type, r_offset,
   4.365 +                    r_addend, name, elf_uval(elf, sym, st_value), sname, sbase,
   4.366 +                    addr, value);
   4.367 +        }
   4.368 +
   4.369 +        if ( relocs[machine].func(elf, r_type, addr, value) == -1 )
   4.370 +        {
   4.371 +            elf_err(elf, "%s: unknown/unsupported reloc type %s [%d]\n",
   4.372 +                    __FUNCTION__, rela_name(machine, r_type), r_type);
   4.373 +            return -1;
   4.374 +        }
   4.375      }
   4.376      return 0;
   4.377  }
   4.378 @@ -316,30 +319,40 @@ int elf_reloc(struct elf_binary *elf)
   4.379      uint64_t i, count, type;
   4.380  
   4.381      count = elf_shdr_count(elf);
   4.382 -    for (i = 0; i < count; i++)
   4.383 +    for ( i = 0; i < count; i++ )
   4.384      {
   4.385 -	rels = elf_shdr_by_index(elf, i);
   4.386 -	type = elf_uval(elf, rels, sh_type);
   4.387 -	if (type != SHT_REL && type != SHT_RELA)
   4.388 -	    continue;
   4.389 -
   4.390 -	sect = elf_shdr_by_index(elf, elf_uval(elf, rels, sh_info));
   4.391 -	syms = elf_shdr_by_index(elf, elf_uval(elf, rels, sh_link));
   4.392 -	if (NULL == sect || NULL == syms)
   4.393 -	    continue;
   4.394 +        rels = elf_shdr_by_index(elf, i);
   4.395 +        type = elf_uval(elf, rels, sh_type);
   4.396 +        if ( (type != SHT_REL) && (type != SHT_RELA) )
   4.397 +            continue;
   4.398  
   4.399 -	if (!(elf_uval(elf, sect, sh_flags) & SHF_ALLOC))
   4.400 -	{
   4.401 -	    elf_msg(elf, "%s: relocations for %s, skipping\n",
   4.402 -		    __FUNCTION__, elf_section_name(elf, sect));
   4.403 -	    continue;
   4.404 -	}
   4.405 +        sect = elf_shdr_by_index(elf, elf_uval(elf, rels, sh_info));
   4.406 +        syms = elf_shdr_by_index(elf, elf_uval(elf, rels, sh_link));
   4.407 +        if ( NULL == sect || NULL == syms )
   4.408 +            continue;
   4.409  
   4.410 -	elf_msg(elf, "%s: relocations for %s @ 0x%" PRIx64 "\n",
   4.411 -		__FUNCTION__, elf_section_name(elf, sect),
   4.412 -		elf_uval(elf, sect, sh_addr));
   4.413 -	if (0 != elf_reloc_section(elf, rels, sect, syms))
   4.414 -	    return -1;
   4.415 +        if ( !(elf_uval(elf, sect, sh_flags) & SHF_ALLOC) )
   4.416 +        {
   4.417 +            elf_msg(elf, "%s: relocations for %s, skipping\n",
   4.418 +                    __FUNCTION__, elf_section_name(elf, sect));
   4.419 +            continue;
   4.420 +        }
   4.421 +
   4.422 +        elf_msg(elf, "%s: relocations for %s @ 0x%" PRIx64 "\n",
   4.423 +                __FUNCTION__, elf_section_name(elf, sect),
   4.424 +                elf_uval(elf, sect, sh_addr));
   4.425 +        if ( elf_reloc_section(elf, rels, sect, syms) != 0 )
   4.426 +            return -1;
   4.427      }
   4.428      return 0;
   4.429  }
   4.430 +
   4.431 +/*
   4.432 + * Local variables:
   4.433 + * mode: C
   4.434 + * c-set-style: "BSD"
   4.435 + * c-basic-offset: 4
   4.436 + * tab-width: 4
   4.437 + * indent-tabs-mode: nil
   4.438 + * End:
   4.439 + */
     5.1 --- a/xen/common/libelf/libelf-tools.c	Wed Feb 14 16:05:28 2007 +0000
     5.2 +++ b/xen/common/libelf/libelf-tools.c	Wed Feb 14 16:06:10 2007 +0000
     5.3 @@ -7,7 +7,7 @@
     5.4  /* ------------------------------------------------------------------------ */
     5.5  
     5.6  uint64_t elf_access_unsigned(struct elf_binary * elf, const void *ptr,
     5.7 -			     uint64_t offset, size_t size)
     5.8 +                             uint64_t offset, size_t size)
     5.9  {
    5.10      int need_swap = elf_swap(elf);
    5.11      const uint8_t *u8;
    5.12 @@ -15,27 +15,27 @@ uint64_t elf_access_unsigned(struct elf_
    5.13      const uint32_t *u32;
    5.14      const uint64_t *u64;
    5.15  
    5.16 -    switch (size)
    5.17 +    switch ( size )
    5.18      {
    5.19      case 1:
    5.20 -	u8 = ptr + offset;
    5.21 -	return *u8;
    5.22 +        u8 = ptr + offset;
    5.23 +        return *u8;
    5.24      case 2:
    5.25 -	u16 = ptr + offset;
    5.26 -	return need_swap ? bswap_16(*u16) : *u16;
    5.27 +        u16 = ptr + offset;
    5.28 +        return need_swap ? bswap_16(*u16) : *u16;
    5.29      case 4:
    5.30 -	u32 = ptr + offset;
    5.31 -	return need_swap ? bswap_32(*u32) : *u32;
    5.32 +        u32 = ptr + offset;
    5.33 +        return need_swap ? bswap_32(*u32) : *u32;
    5.34      case 8:
    5.35 -	u64 = ptr + offset;
    5.36 -	return need_swap ? bswap_64(*u64) : *u64;
    5.37 +        u64 = ptr + offset;
    5.38 +        return need_swap ? bswap_64(*u64) : *u64;
    5.39      default:
    5.40 -	return 0;
    5.41 +        return 0;
    5.42      }
    5.43  }
    5.44  
    5.45  int64_t elf_access_signed(struct elf_binary *elf, const void *ptr,
    5.46 -			  uint64_t offset, size_t size)
    5.47 +                          uint64_t offset, size_t size)
    5.48  {
    5.49      int need_swap = elf_swap(elf);
    5.50      const int8_t *s8;
    5.51 @@ -43,22 +43,22 @@ int64_t elf_access_signed(struct elf_bin
    5.52      const int32_t *s32;
    5.53      const int64_t *s64;
    5.54  
    5.55 -    switch (size)
    5.56 +    switch ( size )
    5.57      {
    5.58      case 1:
    5.59 -	s8 = ptr + offset;
    5.60 -	return *s8;
    5.61 +        s8 = ptr + offset;
    5.62 +        return *s8;
    5.63      case 2:
    5.64 -	s16 = ptr + offset;
    5.65 -	return need_swap ? bswap_16(*s16) : *s16;
    5.66 +        s16 = ptr + offset;
    5.67 +        return need_swap ? bswap_16(*s16) : *s16;
    5.68      case 4:
    5.69 -	s32 = ptr + offset;
    5.70 -	return need_swap ? bswap_32(*s32) : *s32;
    5.71 +        s32 = ptr + offset;
    5.72 +        return need_swap ? bswap_32(*s32) : *s32;
    5.73      case 8:
    5.74 -	s64 = ptr + offset;
    5.75 -	return need_swap ? bswap_64(*s64) : *s64;
    5.76 +        s64 = ptr + offset;
    5.77 +        return need_swap ? bswap_64(*s64) : *s64;
    5.78      default:
    5.79 -	return 0;
    5.80 +        return 0;
    5.81      }
    5.82  }
    5.83  
    5.84 @@ -88,11 +88,12 @@ const elf_shdr *elf_shdr_by_name(struct 
    5.85      const char *sname;
    5.86      int i;
    5.87  
    5.88 -    for (i = 0; i < count; i++) {
    5.89 -	shdr = elf_shdr_by_index(elf, i);
    5.90 -	sname = elf_section_name(elf, shdr);
    5.91 -	if (sname && 0 == strcmp(sname, name))
    5.92 -	    return shdr;
    5.93 +    for ( i = 0; i < count; i++ )
    5.94 +    {
    5.95 +        shdr = elf_shdr_by_index(elf, i);
    5.96 +        sname = elf_section_name(elf, shdr);
    5.97 +        if ( sname && !strcmp(sname, name) )
    5.98 +            return shdr;
    5.99      }
   5.100      return NULL;
   5.101  }
   5.102 @@ -100,31 +101,35 @@ const elf_shdr *elf_shdr_by_name(struct 
   5.103  const elf_shdr *elf_shdr_by_index(struct elf_binary *elf, int index)
   5.104  {
   5.105      uint64_t count = elf_shdr_count(elf);
   5.106 -    const void *ptr = NULL;
   5.107 +    const void *ptr;
   5.108  
   5.109 -    if (index < count)
   5.110 -	ptr = elf->image
   5.111 -	    + elf_uval(elf, elf->ehdr, e_shoff)
   5.112 -	    + elf_uval(elf, elf->ehdr, e_shentsize) * index;
   5.113 +    if ( index >= count )
   5.114 +        return NULL;
   5.115 +
   5.116 +    ptr = (elf->image
   5.117 +           + elf_uval(elf, elf->ehdr, e_shoff)
   5.118 +           + elf_uval(elf, elf->ehdr, e_shentsize) * index);
   5.119      return ptr;
   5.120  }
   5.121  
   5.122  const elf_phdr *elf_phdr_by_index(struct elf_binary *elf, int index)
   5.123  {
   5.124      uint64_t count = elf_uval(elf, elf->ehdr, e_phnum);
   5.125 -    const void *ptr = NULL;
   5.126 +    const void *ptr;
   5.127  
   5.128 -    if (index < count)
   5.129 -	ptr = elf->image
   5.130 -	    + elf_uval(elf, elf->ehdr, e_phoff)
   5.131 -	    + elf_uval(elf, elf->ehdr, e_phentsize) * index;
   5.132 +    if ( index >= count )
   5.133 +        return NULL;
   5.134 +
   5.135 +    ptr = (elf->image
   5.136 +           + elf_uval(elf, elf->ehdr, e_phoff)
   5.137 +           + elf_uval(elf, elf->ehdr, e_phentsize) * index);
   5.138      return ptr;
   5.139  }
   5.140  
   5.141  const char *elf_section_name(struct elf_binary *elf, const elf_shdr * shdr)
   5.142  {
   5.143 -    if (NULL == elf->sec_strtab)
   5.144 -	return "unknown";
   5.145 +    if ( elf->sec_strtab == NULL )
   5.146 +        return "unknown";
   5.147      return elf->sec_strtab + elf_uval(elf, shdr, sh_name);
   5.148  }
   5.149  
   5.150 @@ -136,7 +141,7 @@ const void *elf_section_start(struct elf
   5.151  const void *elf_section_end(struct elf_binary *elf, const elf_shdr * shdr)
   5.152  {
   5.153      return elf->image
   5.154 -	+ elf_uval(elf, shdr, sh_offset) + elf_uval(elf, shdr, sh_size);
   5.155 +        + elf_uval(elf, shdr, sh_offset) + elf_uval(elf, shdr, sh_size);
   5.156  }
   5.157  
   5.158  const elf_sym *elf_sym_by_name(struct elf_binary *elf, const char *symbol)
   5.159 @@ -146,16 +151,16 @@ const elf_sym *elf_sym_by_name(struct el
   5.160      const elf_sym *sym;
   5.161      uint64_t info, name;
   5.162  
   5.163 -    for (; ptr < end; ptr += elf_size(elf, sym))
   5.164 +    for ( ; ptr < end; ptr += elf_size(elf, sym) )
   5.165      {
   5.166 -	sym = ptr;
   5.167 -	info = elf_uval(elf, sym, st_info);
   5.168 -	name = elf_uval(elf, sym, st_name);
   5.169 -	if (ELF32_ST_BIND(info) != STB_GLOBAL)
   5.170 -	    continue;
   5.171 -	if (strcmp(elf->sym_strtab + name, symbol) != 0)
   5.172 -	    continue;
   5.173 -	return sym;
   5.174 +        sym = ptr;
   5.175 +        info = elf_uval(elf, sym, st_info);
   5.176 +        name = elf_uval(elf, sym, st_name);
   5.177 +        if ( ELF32_ST_BIND(info) != STB_GLOBAL )
   5.178 +            continue;
   5.179 +        if ( strcmp(elf->sym_strtab + name, symbol) )
   5.180 +            continue;
   5.181 +        return sym;
   5.182      }
   5.183      return NULL;
   5.184  }
   5.185 @@ -192,9 +197,9 @@ uint64_t elf_note_numeric(struct elf_bin
   5.186      case 2:
   5.187      case 4:
   5.188      case 8:
   5.189 -	return elf_access_unsigned(elf, desc, 0, descsz);
   5.190 +        return elf_access_unsigned(elf, desc, 0, descsz);
   5.191      default:
   5.192 -	return 0;
   5.193 +        return 0;
   5.194      }
   5.195  }
   5.196  const elf_note *elf_note_next(struct elf_binary *elf, const elf_note * note)
   5.197 @@ -211,9 +216,7 @@ int elf_is_elfbinary(const void *image)
   5.198  {
   5.199      const Elf32_Ehdr *ehdr = image;
   5.200  
   5.201 -    if (IS_ELF(*ehdr))
   5.202 -	return 1;
   5.203 -    return 0;
   5.204 +    return IS_ELF(*ehdr);
   5.205  }
   5.206  
   5.207  int elf_phdr_is_loadable(struct elf_binary *elf, const elf_phdr * phdr)
   5.208 @@ -223,3 +226,13 @@ int elf_phdr_is_loadable(struct elf_bina
   5.209  
   5.210      return ((p_type == PT_LOAD) && (p_flags & (PF_W | PF_X)) != 0);
   5.211  }
   5.212 +
   5.213 +/*
   5.214 + * Local variables:
   5.215 + * mode: C
   5.216 + * c-set-style: "BSD"
   5.217 + * c-basic-offset: 4
   5.218 + * tab-width: 4
   5.219 + * indent-tabs-mode: nil
   5.220 + * End:
   5.221 + */