DynASM: Fix global label references
ARM64 patch contributed by Hao Sun and Nick Gasson.
This commit is contained in:
@@ -294,7 +294,7 @@ int dasm_link(Dst_DECL, size_t *szp)
|
|||||||
|
|
||||||
{ /* Handle globals not defined in this translation unit. */
|
{ /* Handle globals not defined in this translation unit. */
|
||||||
int idx;
|
int idx;
|
||||||
for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) {
|
for (idx = 10; idx*sizeof(int) < D->lgsize; idx++) {
|
||||||
int n = D->lglabels[idx];
|
int n = D->lglabels[idx];
|
||||||
/* Undefined label: Collapse rel chain and replace with marker (< 0). */
|
/* Undefined label: Collapse rel chain and replace with marker (< 0). */
|
||||||
while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }
|
while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }
|
||||||
@@ -371,7 +371,10 @@ int dasm_encode(Dst_DECL, void *buffer)
|
|||||||
ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0xe1a00000;
|
ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0xe1a00000;
|
||||||
break;
|
break;
|
||||||
case DASM_REL_LG:
|
case DASM_REL_LG:
|
||||||
CK(n >= 0, UNDEF_LG);
|
if (n < 0) {
|
||||||
|
n = (int)((ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp - 4);
|
||||||
|
goto patchrel;
|
||||||
|
}
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
case DASM_REL_PC:
|
case DASM_REL_PC:
|
||||||
CK(n >= 0, UNDEF_PC);
|
CK(n >= 0, UNDEF_PC);
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ int dasm_link(Dst_DECL, size_t *szp)
|
|||||||
|
|
||||||
{ /* Handle globals not defined in this translation unit. */
|
{ /* Handle globals not defined in this translation unit. */
|
||||||
int idx;
|
int idx;
|
||||||
for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) {
|
for (idx = 10; idx*sizeof(int) < D->lgsize; idx++) {
|
||||||
int n = D->lglabels[idx];
|
int n = D->lglabels[idx];
|
||||||
/* Undefined label: Collapse rel chain and replace with marker (< 0). */
|
/* Undefined label: Collapse rel chain and replace with marker (< 0). */
|
||||||
while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }
|
while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }
|
||||||
@@ -432,7 +432,10 @@ int dasm_encode(Dst_DECL, void *buffer)
|
|||||||
ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0xe1a00000;
|
ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0xe1a00000;
|
||||||
break;
|
break;
|
||||||
case DASM_REL_LG:
|
case DASM_REL_LG:
|
||||||
CK(n >= 0, UNDEF_LG);
|
if (n < 0) {
|
||||||
|
n = (int)((ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp + 4);
|
||||||
|
goto patchrel;
|
||||||
|
}
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
case DASM_REL_PC:
|
case DASM_REL_PC:
|
||||||
CK(n >= 0, UNDEF_PC);
|
CK(n >= 0, UNDEF_PC);
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ int dasm_link(Dst_DECL, size_t *szp)
|
|||||||
|
|
||||||
{ /* Handle globals not defined in this translation unit. */
|
{ /* Handle globals not defined in this translation unit. */
|
||||||
int idx;
|
int idx;
|
||||||
for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) {
|
for (idx = 10; idx*sizeof(int) < D->lgsize; idx++) {
|
||||||
int n = D->lglabels[idx];
|
int n = D->lglabels[idx];
|
||||||
/* Undefined label: Collapse rel chain and replace with marker (< 0). */
|
/* Undefined label: Collapse rel chain and replace with marker (< 0). */
|
||||||
while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }
|
while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }
|
||||||
@@ -349,7 +349,10 @@ int dasm_encode(Dst_DECL, void *buffer)
|
|||||||
ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x60000000;
|
ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x60000000;
|
||||||
break;
|
break;
|
||||||
case DASM_REL_LG:
|
case DASM_REL_LG:
|
||||||
CK(n >= 0, UNDEF_LG);
|
if (n < 0) {
|
||||||
|
n = (int)((ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp);
|
||||||
|
goto patchrel;
|
||||||
|
}
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
case DASM_REL_PC:
|
case DASM_REL_PC:
|
||||||
CK(n >= 0, UNDEF_PC);
|
CK(n >= 0, UNDEF_PC);
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ int dasm_link(Dst_DECL, size_t *szp)
|
|||||||
|
|
||||||
{ /* Handle globals not defined in this translation unit. */
|
{ /* Handle globals not defined in this translation unit. */
|
||||||
int idx;
|
int idx;
|
||||||
for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) {
|
for (idx = 10; idx*sizeof(int) < D->lgsize; idx++) {
|
||||||
int n = D->lglabels[idx];
|
int n = D->lglabels[idx];
|
||||||
/* Undefined label: Collapse rel chain and replace with marker (< 0). */
|
/* Undefined label: Collapse rel chain and replace with marker (< 0). */
|
||||||
while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }
|
while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }
|
||||||
@@ -353,7 +353,10 @@ int dasm_encode(Dst_DECL, void *buffer)
|
|||||||
ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x60000000;
|
ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x60000000;
|
||||||
break;
|
break;
|
||||||
case DASM_REL_LG:
|
case DASM_REL_LG:
|
||||||
CK(n >= 0, UNDEF_LG);
|
if (n < 0) {
|
||||||
|
n = (int)((ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp);
|
||||||
|
goto patchrel;
|
||||||
|
}
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
case DASM_REL_PC:
|
case DASM_REL_PC:
|
||||||
CK(n >= 0, UNDEF_PC);
|
CK(n >= 0, UNDEF_PC);
|
||||||
|
|||||||
Reference in New Issue
Block a user