@@ -349,9 +349,9 @@ void elfObjectApplyRelocations(g_fd file, g_elf_object* object)
349349
350350 // Symbol lookup
351351 if (type == R_X86_64_32 || type == R_X86_64_PC32 ||
352- type == R_X86_64_GLOB_DAT || type == R_X86_64_JMP_SLOT ||
353- type == R_X86_64_GOT32 || type == R_X86_64_TLS_TPOFF ||
354- type == R_X86_64_TLS_DTPMOD32 || type == R_X86_64_TLS_DTPOFF32 ||
352+ type == R_X86_64_GLOB_DAT || type == R_X86_64_JUMP_SLOT ||
353+ type == R_X86_64_GOT32 || type == R_X86_64_TPOFF64 ||
354+ type == R_X86_64_DTPMOD64 || type == R_X86_64_DTPOFF64 ||
355355 type == R_X86_64_COPY)
356356 {
357357 Elf64_Sym* symbol = &object->dynamicSymbolTable [symbolIndex];
@@ -401,59 +401,65 @@ void elfObjectApplyRelocations(g_fd file, g_elf_object* object)
401401 if (type == R_X86_64_32)
402402 {
403403 int32_t cA = *((int32_t *) cP);
404- *((uint32_t *) cP) = cS + cA;
404+ *((uint32_t *) cP) = ( uint32_t ) ( cS + cA) ;
405405 }
406406 else if (type == R_X86_64_PC32)
407407 {
408408 int32_t cA = *((int32_t *) cP);
409- *((uint32_t *) cP) = cS + cA - cP ;
409+ *((uint32_t *) cP) = ( uint32_t ) (( uint64_t ) cS + cA - ( uint64_t ) cP) ;
410410 }
411411 else if (type == R_X86_64_COPY)
412412 {
413413 if (cS)
414414 memoryCopy ((void *) cP, (void *) cS, symbolSize);
415415 }
416- else if (type == R_X86_64_GLOB_DAT)
416+ else if (type == R_X86_64_GLOB_DAT || type == R_X86_64_JUMP_SLOT )
417417 {
418- *((uint32_t *) cP) = cS;
419- }
420- else if (type == R_X86_64_JMP_SLOT)
421- {
422- *((uint32_t *) cP) = cS;
418+ *((uint64_t *) cP) = cS;
423419 }
424420 else if (type == R_X86_64_RELATIVE)
425421 {
426- uint32_t cB = object->baseAddress ;
422+ uint64_t cB = object->baseAddress ;
427423 int32_t cA = *((int32_t *) cP);
428- *((uint32_t *) cP) = cB + cA;
424+ *((uint64_t *) cP) = cB + cA;
425+ }
426+ else if (type == R_X86_64_64)
427+ {
428+ int64_t cA = *((int64_t *) cP);
429+ *((uint64_t *) cP) = cS + cA;
429430 }
430- else if (type == R_X86_64_TLS_TPOFF )
431+ else if (type == R_X86_64_TPOFF64 )
431432 {
432- /* *
433- * For TLS_TPOFF we insert the offset relative to the g_user_threadlocal which is put
434- * into the segment referenced in GS.
435- */
436433 if (cS)
437- *((uint32_t *) cP) = symbolInfo.object ->tlsPart .offset - rootObject->tlsMaster .userThreadOffset +
434+ *((uint64_t *) cP) = symbolInfo.object ->tlsPart .offset - rootObject->tlsMaster .userThreadOffset +
438435 symbolInfo.value ;
439436 }
440- else if (type == R_X86_64_TLS_DTPMOD32 )
437+ else if (type == R_X86_64_TPOFF32 )
441438 {
442- /* *
443- * DTPMOD32 expects the module ID to be written which will be passed to ___tls_get_addr.
444- */
445439 if (cS)
446- *((uint32_t *) cP) = symbolInfo.object ->id ;
440+ *((uint32_t *) cP) = (uint32_t ) (
441+ symbolInfo.object ->tlsPart .offset - rootObject->tlsMaster .userThreadOffset +
442+ symbolInfo.value );
447443 }
448- else if (type == R_X86_64_TLS_DTPOFF32 )
444+ else if (type == R_X86_64_DTPMOD64 )
449445 {
450- /* *
451- * DTPOFF32 expects the symbol offset to be written which will be passed to ___tls_get_addr.
452- */
453446 if (cS)
454- *((uint32_t *) cP) = symbolInfo.object ->tlsPart .offset - rootObject->tlsMaster .userThreadOffset +
447+ *((uint64_t *) cP) = symbolInfo.object ->id ;
448+ }
449+ else if (type == R_X86_64_DTPOFF64)
450+ {
451+ if (cS)
452+ *((uint64_t *) cP) = symbolInfo.object ->tlsPart .offset - rootObject->tlsMaster .userThreadOffset +
455453 symbolInfo.value ;
456454 }
455+ else if (type == R_X86_64_DTPOFF32)
456+ {
457+ if (cS)
458+ *((uint32_t *) cP) = (uint32_t ) (
459+ symbolInfo.object ->tlsPart .offset - rootObject->tlsMaster .userThreadOffset +
460+ symbolInfo.value );
461+ }
462+
457463
458464 entry++;
459465 }
0 commit comments