Hi,
I'm experiencing a rather unusual situation that isn't making sense to me. I'm not as familiar with linux's shared library mechanisms as I perhaps should be. This code was stripped down from a much larger project, so it'll look a little strange, but it easily demonstrates the questions I'll ask at the bottom on this:
Here is the script I am using to compile this test:
Code:
#!/bin/sh
clear
export DEF="-D_USE_LARGEFILE64 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE"
export SRC="-D_REENTRANT -D_BSD_SOURCE"
export OPT="-w -O3 -march=i686 -mtune=i686 -ffast-math -funroll-loops -fno-exceptions -minline-all-stringops"
gcc -c -o test.o test.c $DEF $SRC $OPT
ar rcs libtest.a test.o
gcc -fPIC -c -o test.o test.c $DEF $SRC $OPT
gcc -shared -Wl,-soname,libtest.so.1 -o libtest.so.1.0.0 test.o -lc
ldconfig -n .
export DEF="-D_USE_LARGEFILE64 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE"
export SRC="-D_REENTRANT -D_BSD_SOURCE"
export SHLIB="-ltest -L."
export OPT="-w -O3 -march=i686 -mtune=i686 -ffast-math -funroll-loops -fno-exceptions -minline-all-stringops"
gcc -o StrICmpTest StrICmpTest.c $DEF $SRC $SHLIB $OPT
Here is my test library code - test.c:
Code:
#include <stdio.h>
#define C unsigned char
#define D double
#define F float
#define I int
#define L long
#define UL2 unsigned long long
#define L2 long long
#define LD long double
#define S struct
#define SC signed char
#define SI signed int
#define STR string
#define U union
#define UC unsigned char
#define UI unsigned int
#define UL unsigned long
#define US unsigned short
#define V void
#define dStrIsLower(c) (c>='a'&&c<='z')
#define dStrIsUpper(c) (c>='A'&&c<='Z')
#define dStrToLower(c) (dStrIsUpper(c)?c-'a'-'A':c)
#define dStrToUpper(c) (dStrIsLower(c)?c+'a'-'A':c)
I stricmp7(C *s1, C *s2)
{
UL i, l1, l2, m;
C d1, d2;
l1=strlen(s1);
l2=strlen(s2);
m=l1<l2?l1:l2;
if(l1!=l2)
return(l1-l2);
for(i=0;i<m;i++)
{
d1=dStrToLower(s1[i]);
d2=dStrToLower(s2[i]);
if(d1!=d2)
return(d1-d2);
}
return(0);
}
The main program - StrICmpTest.c:
Code:
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#define MEGABYTE 1048576
typedef unsigned char string[256];
#define C unsigned char
#define D double
#define F float
#define I int
#define L long
#define UL2 unsigned long long
#define L2 long long
#define LD long double
#define S struct
#define SC signed char
#define SI signed int
#define STR string
#define U union
#define UC unsigned char
#define UI unsigned int
#define UL unsigned long
#define US unsigned short
#define V void
#define dStrIsLower(c) (c>='a'&&c<='z')
#define dStrIsUpper(c) (c>='A'&&c<='Z')
#define dStrToLower(c) (dStrIsUpper(c)?c-'a'-'A':c)
#define dStrToUpper(c) (dStrIsLower(c)?c+'a'-'A':c)
#define NFACTOR 3072
#define NTIMES (NFACTOR*NFACTOR)
I stricmp1(C *s1, C *s2)
{
UL i, l1, l2, m;
C d1, d2;
l1=strlen(s1);
l2=strlen(s2);
m=l1<l2?l1:l2;
if(l1!=l2)
return(l1-l2);
for(i=0;i<m;i++)
{
d1=dStrToLower(s1[i]);
d2=dStrToLower(s2[i]);
if(d1!=d2)
return(d1-d2);
}
return(0);
}
I main(I argc, C *argv[])
{
clock_t st, et;
STR buffer;
I i, l1;
strcpy(buffer,"Hello World ABCDEFGHIJKLMNOPQRSTUVWXYZ");
st=clock();
for(i=0;i<NTIMES;i++) {
l1=strcasecmp(buffer,buffer);
l1=strcasecmp(buffer,"Hello World ABCDEFGHIJKLMNOPQRSTUVWXYZ Kitty"); }
et=clock();
printf("strcasecmp, %f\n",((D)(et-st))/((D)CLOCKS_PER_SEC));
st=clock();
for(i=0;i<NTIMES;i++) {
l1=stricmp1(buffer,buffer);
l1=stricmp1(buffer,"Hello World ABCDEFGHIJKLMNOPQRSTUVWXYZ Kitty"); }
et=clock();
printf("stricmp1, %f\n",((D)(et-st))/((D)CLOCKS_PER_SEC));
st=clock();
for(i=0;i<NTIMES;i++) {
l1=stricmp7(buffer,buffer);
l1=stricmp7(buffer,"Hello World ABCDEFGHIJKLMNOPQRSTUVWXYZ Kitty"); }
et=clock();
printf("stricmp7, %f\n",((D)(et-st))/((D)CLOCKS_PER_SEC));
return(0);
}
Now for the output:
Code:
./MKTlib && ./StrICmpTest
strcasecmp, 0.000000
stricmp1, 0.020000
stricmp7, 1.910000
As you can see, the program runs perfectly. I'm using a full and clean install of Slackware 13.1, gcc version of 4.4.4
Now for the questions:
1. Why does stricmp7 take so much longer to run then stricmp1 when the code of both is identical?
Code:
ldd StrICmpTest
linux-gate.so.1 => (0xb7794000)
libc.so.6 => /lib/libc.so.6 (0xb761b000)
/lib/ld-linux.so.2 (0xb7795000)
2. Why does libtest NOT show up in the above?
3. What can be done to fix this problem?
Thank you in advance.