ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've been racking my brain against this one and I can't figure it out. So I'm trying to compile this code which should make signatures for various methods and such in libc.a but I keep getting this error:
/tmp/ccUn3VTU.o: In function `main':
fprints.c.text+0x21c): undefined reference to `bfd_openr'
fprints.c.text+0x269): undefined reference to `bfd_check_format'
fprints.c.text+0x284): undefined reference to `bfd_check_format_matches'
collect2: ld returned 1 exit status
This is when I'm compiling the program using this command:
g++ -lssl -lbfd fprints.c
I thought that maybe because this code is like 6 years old that it simply was using bfd wrong but since it's an undefined reference then the usage should be valid right?
Any input would be greatly appreciated on this matter.
Just in case this helps I'm including the file which I'm trying to compile... and for the record if anyone knows of some different methods to achieve the same result then please let me know because I just need to get the file that this is supposed to make to work with my other software.
Code:
/*
fenris - program execution path analysis tool
---------------------------------------------
Copyright (C) 2001, 2002 by Bindview Corporation
Portions copyright (C) 2001, 2002 by their respective contributors
Developed and maintained by Michal Zalewski <lcamtuf@coredump.cx>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <bfd.h>
#include <libiberty.h>
#include "libfnprints.h"
#include "config.h"
unsigned char buf[SIGNATSIZE+4];
#define CODESEG (((unsigned int)buf) >> 24)
unsigned int result[4];
MD5_CTX kuku;
int main(int argc,char* argv[]) {
int summ=0;
asymbol** syms;
int size,symcnt,i,off;
bfd* b;
if (argc-2) {
fprintf(stderr,"function signatures for fenris -- <lcamtuf@coredump.cx>\n");
fprintf(stderr,"Usage: %s elf_object\n",argv[0]);
exit(1);
}
b = bfd_openr(argv[1],0);
if (!b) { fprintf(stderr,"bfd_openr failed\n"); exit(1); }
bfd_check_format(b,bfd_archive);
bfd_check_format_matches(b,bfd_object,0);
if ((bfd_get_file_flags(b) & HAS_SYMS) == 0) {
if (!getenv("FANCY")) fprintf(stderr,"No symbols.\n");
else fprintf(stderr,"EMPTY");
exit(1);
}
size=bfd_get_symtab_upper_bound(b);
syms=(asymbol**)malloc(size);
symcnt=bfd_canonicalize_symtab(b,syms);
for (i=0;i<symcnt;i++) {
if (syms[i]->flags & BSF_FUNCTION) {
char name[500],*fiu;
strcpy(name,(char*)(bfd_asymbol_name(syms[i])));
if ((fiu=strstr(&name[2],"__")))
if (*(fiu-1)!='_') *fiu=0;
if ((fiu=strchr(name+1,'@'))) *fiu=0;
if (!strlen(name)) continue;
off=syms[i]->value;
if (syms[i]->section) off+=syms[i]->section->filepos;
{ unsigned int f;
f=open(argv[1],O_RDONLY);
lseek(f,off,SEEK_SET);
summ++;
bzero(buf,sizeof(buf));
read(f,buf,SIGNATSIZE);
f=fnprint_compute(buf,CODESEG);
if (f!=0xA120AD5C) { // Ignore only NOPs
printf("[%s+%d] %s ",argv[1],off,name);
printf("%08X\n",f);
}
}
}
}
if (getenv("FANCY")) fprintf(stderr,"%d function%s",summ,summ==1?"":"s");
else fprintf(stderr,"--> %s: done (%d function%s)\n",argv[1],summ,
summ==1?"":"s");
return 0;
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.