Problems with gmplib execution under x64 arquitecture

Andrew Woolfgang aevr007 at gmail.com
Mon Jul 4 00:13:04 CEST 2011


Hi everyone,  for approximately one year ago i have been working with gmplib
on a cryptographic code, well, the library works fine with my code and have
a good performance under 32 bits arquitecture, all my test was made on my
laptop under a 32 bit enviroment. Later i feel the need to work under a 64
bits arquitecture, and i get some problems on the execution time, the same
code compiled under differents arquitectures give me diferentes result,
apparently the lib doesn't works fine under this arquitecture, i will send
you some usefull information, i hope that you can help me:

$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 26
model name      : Intel(R) Xeon(R) CPU           E5520  @ 2.27GHz
stepping        : 5
cpu MHz         : 2261.230
cache size      : 8192 KB
physical id     : 1
siblings        : 8
core id         : 0
cpu cores       : 4
apicid          : 16
initial apicid  : 16
fpu             : yes
fpu_exception   : yes
cpuid level     : 11
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx
rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc
aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca
sse4_1 sse4_2 popcnt lahf_lm ida tpr_shadow vnmi flexpriority ept vpid
bogomips        : 4522.46
clflush size    : 64
cache_alignment : 64
address sizes   : 40 bits physical, 48 bits virtual

... and 7 others processors

$ uname -a
Linux host 2.6.32-gentoo-r7 #1 SMP Fri Jun 18 18:39:25 CLT 2010 x86_64
Intel(R) Xeon(R) CPU E5520 @ 2.27GHz GenuineIntel GNU/Linux

I compiled on my home directory the 5.0.2 library and the available on the
respositry of debian and gentoo (4.3.2)

The compiler under gentoo x64 bits
gcc (Gentoo Hardened 4.4.5 p1.2, pie-0.4.5) 4.4.5

The compiler under debian
gcc (Debian 4.4.5-8) 4.4.5

The error strack trace under 64 bits arquitecture is:

avillalobos at servapp ~/GMPGaloisField/Debug $ ./GMPGaloisField m 5 k 2 o 1
Galois field Properties
 ##############################################################
         · m = 5
         · Px = 0
         · MaxExponent = -1
         · Felements = 32
         · a^m = 37
 ##############################################################


         ## Finalizando suma ##

*** glibc detected *** ./GMPGaloisField: munmap_chunk(): invalid pointer:
0x00007fff2e9e3324 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x72d25)[0x7f3e8236ed25]
./GMPGaloisField(+0x1aec)[0x7f3e82f88aec]
./GMPGaloisField(+0x43bf)[0x7f3e82f8b3bf]
./GMPGaloisField(+0x4c31)[0x7f3e82f8bc31]
./GMPGaloisField(main+0x2f)[0x7f3e82f8bca5]
/lib64/libc.so.6(__libc_start_main+0xfd)[0x7f3e8231ad6d]
./GMPGaloisField(+0x15a9)[0x7f3e82f885a9]
======= Memory map: ========
7f3e820e5000-7f3e820fb000 r-xp 00000000 08:03 6345778
 /lib64/libgcc_s.so.1
7f3e820fb000-7f3e822fa000 ---p 00016000 08:03 6345778
 /lib64/libgcc_s.so.1
7f3e822fa000-7f3e822fb000 r--p 00015000 08:03 6345778
 /lib64/libgcc_s.so.1
7f3e822fb000-7f3e822fc000 rw-p 00016000 08:03 6345778
 /lib64/libgcc_s.so.1
7f3e822fc000-7f3e82459000 r-xp 00000000 08:03 6697328
 /lib64/libc-2.12.2.so
7f3e82459000-7f3e82659000 ---p 0015d000 08:03 6697328
 /lib64/libc-2.12.2.so
7f3e82659000-7f3e8265d000 r--p 0015d000 08:03 6697328
 /lib64/libc-2.12.2.so
7f3e8265d000-7f3e8265e000 rw-p 00161000 08:03 6697328
 /lib64/libc-2.12.2.so
7f3e8265e000-7f3e82663000 rw-p 00000000 00:00 0
7f3e82663000-7f3e82670000 r-xp 00000000 08:03 6949757
 /usr/lib64/libconfig.so.9.1.1
7f3e82670000-7f3e8286f000 ---p 0000d000 08:03 6949757
 /usr/lib64/libconfig.so.9.1.1
7f3e8286f000-7f3e82870000 r--p 0000c000 08:03 6949757
 /usr/lib64/libconfig.so.9.1.1
7f3e82870000-7f3e82871000 rw-p 0000d000 08:03 6949757
 /usr/lib64/libconfig.so.9.1.1
7f3e82871000-7f3e828dd000 r-xp 00000000 08:04 11014457
/home/avillalobos/gmp-5.0.2/.libs/libgmp.so.10.0.2
7f3e828dd000-7f3e82adc000 ---p 0006c000 08:04 11014457
/home/avillalobos/gmp-5.0.2/.libs/libgmp.so.10.0.2
7f3e82adc000-7f3e82ade000 r--p 0006b000 08:04 11014457
/home/avillalobos/gmp-5.0.2/.libs/libgmp.so.10.0.2
7f3e82ade000-7f3e82ae6000 rw-p 0006d000 08:04 11014457
/home/avillalobos/gmp-5.0.2/.libs/libgmp.so.10.0.2
7f3e82ae6000-7f3e82b65000 r-xp 00000000 08:03 6697286
 /lib64/libm-2.12.2.so
7f3e82b65000-7f3e82d65000 ---p 0007f000 08:03 6697286
 /lib64/libm-2.12.2.so
7f3e82d65000-7f3e82d66000 r--p 0007f000 08:03 6697286
 /lib64/libm-2.12.2.so
7f3e82d66000-7f3e82d67000 rw-p 00080000 08:03 6697286
 /lib64/libm-2.12.2.so
7f3e82d67000-7f3e82d85000 r-xp 00000000 08:03 6697379
 /lib64/ld-2.12.2.so
7f3e82f66000-7f3e82f6a000 rw-p 00000000 00:00 0
7f3e82f82000-7f3e82f84000 rw-p 00000000 00:00 0
7f3e82f84000-7f3e82f85000 r--p 0001d000 08:03 6697379
 /lib64/ld-2.12.2.so
7f3e82f85000-7f3e82f86000 rw-p 0001e000 08:03 6697379
 /lib64/ld-2.12.2.so
7f3e82f86000-7f3e82f87000 rw-p 00000000 00:00 0
7f3e82f87000-7f3e82f8d000 r-xp 00000000 08:04 11011183
/home/avillalobos/GMPGaloisField/Debug/GMPGaloisField
7f3e8318c000-7f3e8318d000 r--p 00005000 08:04 11011183
/home/avillalobos/GMPGaloisField/Debug/GMPGaloisField
7f3e8318d000-7f3e8318e000 rw-p 00006000 08:04 11011183
/home/avillalobos/GMPGaloisField/Debug/GMPGaloisField
7f3e8318e000-7f3e831af000 rw-p 00000000 00:00 0
 [heap]
7fff2e9e0000-7fff2e9e4000 rw-p 00000000 00:00 0
 [stack]
7fff2e9ff000-7fff2ea00000 r-xp 00000000 00:00 0
 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0
 [vsyscall]
Abortado

And the same execution under a 32 bit arquitecture.

Galois field Properties
 ##############################################################
         · m = 5
         · Px = 37
         · MaxExponent = 31
         · Felements = 32
         · a^m = 5
 ##############################################################

        ## a[1]^0 + a[1]^0 ##
[ Result of addition  =  a[0]^-27 ]
###########################################################
        ## a[1]^0 + a[2]^1 ##
[ Result of addition  =  a[3]^18 ]
###########################################################
 ..... [Here there are a lot of addition operations ]
###########################################################
        ## a[1]^0 + a[1]^0 ##
[ Result of addition  =  a[0]^-27 ]
###########################################################

         ## Finalizando suma ##


As you can see, under a 32 bit arquitecture, the code works fine, but if i
execute the same code without changes into a 64 bits arquitecture, the libs
doesn't works fine and doesn't give good results.

Also, here is a piece of code related with the generation of
GaloisFieldProperties.

k = 2
m = 5

GaloisFieldProperties* CreateGaloisField_k(int k,unsigned int m){
GaloisFieldProperties* GaloisField = (GaloisFieldProperties*) malloc
(sizeof(GaloisFieldProperties));
GaloisField->m = m;
GaloisField->aM = (GaloisElement*) malloc (sizeof(GaloisElement));
// initializing the mpz_t variable to store the quantity of elements inside
of this galois field
mpz_init(GaloisField->Felements);
// getting the quantity of alphas on this galois field
mpz_ui_pow_ui(GaloisField->Felements,2,m);

mpz_init(GaloisField->MaxExponent);
mpz_sub_ui(GaloisField->MaxExponent,GaloisField->Felements,1);
mpz_t temp;
mpz_init(temp);

// getting a^k
mpz_ui_pow_ui(temp,2,k);

// initializing mpz_t variable to store a^m
mpz_init(GaloisField->aM->PolynomialRepresentation);
mpz_init(GaloisField->aM->Exponent);

mpz_set_ui(GaloisField->aM->Exponent,m);

// creating a^m, using this equation: a^m + a^k + 1 = 0 /+a^m => a^m = a^k +
1, then here we are using temp as a^k and we
// are adding 1, so aM = temp + 1
mpz_add_ui(GaloisField->aM->PolynomialRepresentation,temp,1);

// Creating the Primitive polynomial with p(x) = a^m + a^k + 1
mpz_init(GaloisField->PrimitivePolynomial);
mpz_add(GaloisField->PrimitivePolynomial,GaloisField->Felements,GaloisField->aM->PolynomialRepresentation);
mpz_clear(temp);
return GaloisField;
}

If you have some usefull information please respond this thread, i will be
gratefull. Thanks, and read you later.

 Atte Andrés Villalobos

--

ANDRÉS EDUARDO VILLALOBOS RIVERA
INGENIERÍA EJECUCIÓN EN COMPUTACIÓN  E INFORMÁTICA
FACULTAD DE INGENIERÍA Y CIENCIAS GEOLÓGICAS
UNIVERSIDAD CATÓLICA DEL NORTE

[image: Linux Logo]

*"Lo que tú aprendes, todos lo aprendemos, *
*lo que tú sabes, nos beneficia a todos"*


More information about the gmp-bugs mailing list