Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR#5059: split objinfo into a pure Caml part and a pure C part.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10459 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
- Loading branch information
1 parent
bcb5a6b
commit cd648ee
Showing
5 changed files
with
134 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/***********************************************************************/ | ||
/* */ | ||
/* Objective Caml */ | ||
/* */ | ||
/* Mehdi Dogguy, PPS laboratory, University Paris Diderot */ | ||
/* */ | ||
/* Copyright 2010 Mehdi Dogguy. Used and distributed as part of */ | ||
/* Objective Caml by permission from the author. This file is */ | ||
/* distributed under the terms of the Q Public License version 1.0. */ | ||
/***********************************************************************/ | ||
|
||
#include "../config/s.h" | ||
#include "../byterun/mlvalues.h" | ||
#include "../byterun/alloc.h" | ||
#include <stdio.h> | ||
|
||
#ifdef HAS_LIBBFD | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <bfd.h> | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
bfd *fd; | ||
asection *sec; | ||
file_ptr offset; | ||
long st_size; | ||
asymbol ** symbol_table; | ||
long sym_count, i; | ||
|
||
if (argc != 2) { | ||
fprintf(stderr, "Usage: objinfo_helper <dynamic library>\n"); | ||
return 2; | ||
} | ||
|
||
fd = bfd_openr(argv[1], "default"); | ||
if (!fd) { | ||
fprintf(stderr, "Error opening file %s\n", argv[1]); | ||
return 2; | ||
} | ||
if (! bfd_check_format (fd, bfd_object)) { | ||
fprintf(stderr, "Error: wrong format\n"); | ||
bfd_close(fd); | ||
return 2; | ||
} | ||
|
||
sec = bfd_get_section_by_name(fd, ".data"); | ||
if (! sec) { | ||
fprintf(stderr, "Error: section .data not found\n"); | ||
bfd_close(fd); | ||
return 2; | ||
} | ||
|
||
offset = sec->filepos; | ||
st_size = bfd_get_dynamic_symtab_upper_bound (fd); | ||
if (st_size <= 0) { | ||
fprintf(stderr, "Error: size of section .data unknown\n"); | ||
bfd_close(fd); | ||
return 2; | ||
} | ||
|
||
symbol_table = malloc(st_size); | ||
if (! symbol_table) { | ||
fprintf(stderr, "Error: out of memory\n"); | ||
bfd_close(fd); | ||
return 2; | ||
} | ||
|
||
sym_count = bfd_canonicalize_dynamic_symtab (fd, symbol_table); | ||
|
||
for (i = 0; i < sym_count; i++) { | ||
if (strcmp(symbol_table[i]->name, "caml_plugin_header") == 0) { | ||
printf("%ld\n", (long) (offset + symbol_table[i]->value)); | ||
bfd_close(fd); | ||
return 0; | ||
} | ||
} | ||
|
||
fprintf(stderr, "Error: missing symbol caml_plugin_header\n"); | ||
bfd_close(fd); | ||
return 2; | ||
} | ||
|
||
#else | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
fprintf(stderr, "BFD library unavailable, cannot print info on .cmxs files\n"); | ||
return 2; | ||
} | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.