Skip to content

Commit 3a5582e

Browse files
committed
fix relocations in inline asm; there are still gotchas, but some basic examples work
1 parent f3cf03c commit 3a5582e

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

backends/asm/assemble_ir.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ OutputAlignLong(Flexbuf *fb)
462462
}
463463

464464
void
465-
OutputDataBlob(Flexbuf *fb, Flexbuf *databuf, Flexbuf *relocbuf, const char *startLabel)
465+
OutputDataBlob(Flexbuf *fb, Flexbuf *databuf, Flexbuf *relocbuf, const char *startLabel, bool outLabel)
466466
{
467467
uint8_t *data;
468468
int len;
@@ -472,7 +472,7 @@ OutputDataBlob(Flexbuf *fb, Flexbuf *databuf, Flexbuf *relocbuf, const char *sta
472472
uint32_t runlen;
473473
int lastdata;
474474

475-
if (startLabel) {
475+
if (outLabel && startLabel) {
476476
OutputAlignLong(fb);
477477
flexbuf_printf(fb, startLabel);
478478
flexbuf_printf(fb, "\n");
@@ -675,7 +675,7 @@ OutputDataBlob(Flexbuf *fb, Flexbuf *databuf, Flexbuf *relocbuf, const char *sta
675675
}
676676

677677
static void
678-
OutputBlob(Flexbuf *fb, Operand *label, Operand *op, Module *P)
678+
OutputBlob(Flexbuf *fb, Operand *label, Operand *op, Module *P, bool initLabel)
679679
{
680680
Flexbuf *databuf;
681681
Flexbuf *relocbuf;
@@ -692,7 +692,7 @@ OutputBlob(Flexbuf *fb, Operand *label, Operand *op, Module *P)
692692
}
693693
databuf = (Flexbuf *)op->name;
694694
relocbuf = (Flexbuf *)op->val;
695-
OutputDataBlob(fb, databuf, relocbuf, baseLabel);
695+
OutputDataBlob(fb, databuf, relocbuf, baseLabel, initLabel);
696696
}
697697

698698
/* find string for opcode */
@@ -1450,7 +1450,7 @@ DoAssembleIR(struct flexbuf *fb, IR *ir, Module *P)
14501450
// dst has a label (or is NULL for no label)
14511451
// src has the data in a string
14521452
// src2 is re-used as a pointer to the module
1453-
OutputBlob(fb, ir->dst, ir->src, (Module *)ir->src2);
1453+
OutputBlob(fb, ir->dst, ir->src, (Module *)ir->src2, ir->opc == OPC_LABELED_BLOB);
14541454
break;
14551455
case OPC_FIT:
14561456
flexbuf_printf(fb, "\tfit\t");

backends/asm/inlineasm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ CompileMiniDatBlock(IRList *irl, AST *origtop, unsigned asmFlags)
930930
AppendIR(irl, org0);
931931
}
932932
Operand *op = NewOperand(IMM_BINARY, (const char *)fb, (intptr_t)relocs);
933-
ir = EmitOp2(irl, OPC_BINARY_BLOB, NULL, op);
933+
ir = EmitOp2(irl, OPC_BINARY_BLOB, ModData(current)->datlabel, op);
934934
ir->src2 = (Operand *)current;
935935

936936
/* finish off the block */

backends/becommon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
AST *BuildMethodPointer(AST *ast);
99
void OutputAlignLong(Flexbuf *fb);
10-
void OutputDataBlob(Flexbuf *fb, Flexbuf *databuf, Flexbuf *relocbuf, const char *startLabel);
10+
void OutputDataBlob(Flexbuf *fb, Flexbuf *databuf, Flexbuf *relocbuf, const char *startLabel, bool emitLabel);
1111

1212
void NormalizeVarOffsets(Function *f);
1313

backends/nucode/outnu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,7 +2453,7 @@ static int NuCompileObject(void *vptr, Module *P) {
24532453
PrintDataBlock(&datBuf,P->datblock,NULL,&datRelocs);
24542454
OutputAlignLong(&datBuf);
24552455
//NuOutputLabelNL(fb, ModData(P)->datLabel); // actually done by OutputDataBlob
2456-
OutputDataBlob(fb, &datBuf, &datRelocs, NuLabelName(ModData(P)->datLabel));
2456+
OutputDataBlob(fb, &datBuf, &datRelocs, NuLabelName(ModData(P)->datLabel), true);
24572457

24582458
flexbuf_delete(&datRelocs);
24592459
flexbuf_delete(&datBuf);
@@ -2470,7 +2470,7 @@ static int NuCompileObject(void *vptr, Module *P) {
24702470
NuOutputIrList(fb, &FunData(pf)->irl);
24712471
if (FunData(pf)->dataLabel) {
24722472
NuOutputLabelNL(fb, FunData(pf)->dataLabel);
2473-
OutputDataBlob(fb, &FunData(pf)->dataBuf, &FunData(pf)->dataBufRelocs, NULL);
2473+
OutputDataBlob(fb, &FunData(pf)->dataBuf, &FunData(pf)->dataBufRelocs, NuLabelName(ModData(P)->datLabel), false);
24742474
}
24752475
}
24762476
return 1;

0 commit comments

Comments
 (0)