I'll state off the bat that I'm not a programmer, and am probably in over my head.
I'm trying to track down a bug in in the __strlen_sse2 (assembly) function installed in Debian as part of libc6-i686.
I already have a copy of the assembly code (.S file) and I need to figure out a way to call it from a C/C++ program. How can I achieve this?
edit:
Tried this code, but I get an 开发者_如何学Pythonerror from gcc about undefined reference to '__strlen_sse2'
edit 2: It's my understanding that this is the proper answer to the question, but I lack the proper knowledge to carry it to completion. Thanks for the help everyone.
#include <stdio.h>
#include <string.h>
size_t __strlen_sse2(const char *);
void main()
{
char buffer[255];
printf("Standby.. ");
gets(buffer);
__strlen_sse2("CRASH!");
printf("OK!\n");
}
Like I said... not a programmer.
I hope my question makes sense. Please let me know if you need any more information.
You can't directly call the copy of __strlen_sse2
inside the usual, dynamically-linked /lib/libc.so.6
because it is a "hidden symbol" -- accessible to code inside libc itself, but not available for external linking.
You say you have the .S
file that defines __strlen_sse2
, from glibc's source code, but you're going to need to modify it to be buildable outside glibc. I found what I think is the right file, and was able to modify it pretty easily. Delete everything up to but not including the line that reads just
.text
and replace it with this:
#define PUSH(REG) pushl REG
#define POP(REG) popl REG
#define PARMS 4
#define STR PARMS
#define ENTRANCE
#define RETURN ret
#define L(x) .L##x
#define ENTRY(x) .globl x; .type x,@function; x:
#define END(x) .size x, .-x
Also delete the #endif
line at the very end of the file. Then compile like so:
gcc -m32 -c strlen-sse2.S
gcc -m32 -c test.c
gcc -m32 test.o strlen-sse2.o
./a.out
You may not need the -m32
s.
You might be able to get some help with your larger problem from superuser.com -- provide the contents of /proc/cpuinfo
in your question.
Just declare the function, preferably with a full prototype, and call it. This is probably the right prototype:
size_t __strlen_sse2(const char *);
I'm a bit skeptical of your claim that you're trying to track down a bug in this function. It's more likely there's a bug in your program that's calling strlen
with an invalid argument (either an invalid pointer or a pointer to something other than a null-terminated string).
精彩评论