#define ADDR_SIZE 32
#endif
+static int use_stdin, use_stdout;
static const char *sym_name(struct elf_info *elf, Elf_Sym *sym)
{
{
struct stat st;
void *map = MAP_FAILED;
- int fd;
+ int fd = -1;
+
+ if (!use_stdin) {
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+ } else {
+ /* from stdin, use a temporary file to mmap */
+ FILE *infile;
+ char buffer[1024];
+ size_t n;
+
+ infile = tmpfile();
+ if (infile == NULL) {
+ perror("tmpfile");
+ return NULL;
+ }
+ while (!feof(stdin)) {
+ n = fread(buffer, 1, sizeof(buffer), stdin);
+ if (fwrite(buffer, 1, n, infile) != n)
+ goto failed;
+ }
+ fflush(infile);
+ fd = fileno(infile);
+ }
- fd = open(filename, O_RDONLY);
- if (fd < 0)
- return NULL;
if (fstat(fd, &st))
goto failed;
* There are more than 64k sections,
* read count from .sh_size.
*/
- info->num_sections = TO_NATIVE(endian, 32, sechdrs[0].sh_size);
+ info->num_sections =
+ TO_NATIVE(endian, ADDR_SIZE, sechdrs[0].sh_size);
} else {
info->num_sections = hdr->e_shnum;
}
sechdrs[i].sh_offset =
TO_NATIVE(endian, ADDR_SIZE, sechdrs[i].sh_offset);
sechdrs[i].sh_size =
- TO_NATIVE(endian, 32, sechdrs[i].sh_size);
+ TO_NATIVE(endian, ADDR_SIZE, sechdrs[i].sh_size);
sechdrs[i].sh_link =
TO_NATIVE(endian, 32, sechdrs[i].sh_link);
sechdrs[i].sh_info =
do {
new = calloc(sizeof(struct pmd_driver), 1);
+ if (new == NULL) {
+ fprintf(stderr, "Failed to calloc memory\n");
+ return -1;
+ }
new->name_sym = find_sym_in_symtab(info, "this_pmd_name", last);
last = new->name_sym;
if (!new->name_sym)
struct rte_pci_id *pci_ids;
int idx = 0;
- ofd = fopen(outfile, "w+");
- if (!ofd) {
- fprintf(stderr, "Unable to open output file\n");
- return;
+ if (use_stdout)
+ ofd = stdout;
+ else {
+ ofd = fopen(outfile, "w+");
+ if (!ofd) {
+ fprintf(stderr, "Unable to open output file\n");
+ return;
+ }
}
drv = info->drivers;
basename(argv[0]));
exit(127);
}
+ use_stdin = !strcmp(argv[1], "-");
+ use_stdout = !strcmp(argv[2], "-");
parse_elf(&info, argv[1]);
- locate_pmd_entries(&info);
+ if (locate_pmd_entries(&info) < 0)
+ exit(1);
if (info.drivers) {
output_pmd_info_string(&info, argv[2]);