Skip to content

Commit bd356fe

Browse files
committed
[EVM] Add datasize/dataoffset intrinsics
This includes: - datasize/dataoffset intrinsics - EVM specific ELF relocations
1 parent 790c8b9 commit bd356fe

24 files changed

+306
-56
lines changed

llvm/include/llvm/BinaryFormat/ELF.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ enum {
323323
// EraVM local begin
324324
EM_ERAVM = 260, // EraVM
325325
// EraVM local end
326+
// EVM local begin
327+
EM_EVM = 261 // EVM
328+
// EVM local end
326329
};
327330

328331
// Object file classes.
@@ -426,6 +429,13 @@ enum {
426429
#include "ELFRelocs/AArch64.def"
427430
};
428431

432+
// EVM local begin
433+
// ELF Relocation types for EVM
434+
enum {
435+
#include "ELFRelocs/EVM.def"
436+
};
437+
// EVM local end
438+
429439
// Special values for the st_other field in the symbol table entry for AArch64.
430440
enum {
431441
// Symbol may follow different calling convention than base PCS.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
#ifndef ELF_RELOC
3+
#error "ELF_RELOC must be defined"
4+
#endif
5+
6+
ELF_RELOC(R_EVM_NONE, 0)
7+
ELF_RELOC(R_EVM_DATA, 1)

llvm/include/llvm/IR/IntrinsicsEVM.td

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,20 @@ def int_evm_memcpyas1as4
246246
WriteOnly<ArgIndex<0>>, ReadOnly<ArgIndex<1>>,
247247
ImmArg<ArgIndex<3>>]>;
248248

249+
// The following intrinsics are used for linking purposes.
250+
251+
// Returns a code size of the Yul object with the name
252+
// passed in the metadata.
253+
def int_evm_datasize : DefaultAttrsIntrinsic<
254+
[llvm_i256_ty], [llvm_metadata_ty],
255+
[IntrNoMem, IntrSpeculatable]
256+
>;
257+
258+
// Returns a code offset of the Yul object with the name
259+
// passed in the metadata.
260+
def int_evm_dataoffset : DefaultAttrsIntrinsic<
261+
[llvm_i256_ty], [llvm_metadata_ty],
262+
[IntrNoMem, IntrSpeculatable]
263+
>;
264+
249265
} // TargetPrefix = "evm"

llvm/include/llvm/MC/MCExpr.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,10 @@ class MCSymbolRefExpr : public MCExpr {
357357
VK_VE_TPOFF_LO32, // symbol@tpoff_lo
358358

359359
VK_TPREL,
360-
VK_DTPREL
360+
VK_DTPREL,
361+
// EVM local begin
362+
VK_EVM_DATA,
363+
// EVM local end
361364
};
362365

363366
private:

llvm/include/module.modulemap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ module LLVM_BinaryFormat {
107107
textual header "llvm/BinaryFormat/ELFRelocs/Xtensa.def"
108108
textual header "llvm/BinaryFormat/WasmRelocs.def"
109109
textual header "llvm/BinaryFormat/MsgPack.def"
110+
textual header "llvm/BinaryFormat/EVM.def"
110111
}
111112

112113
module LLVM_Config {

llvm/lib/BinaryFormat/ELF.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ uint16_t ELF::convertArchNameToEMachine(StringRef Arch) {
201201
// EraVM local begin
202202
.Case("eravm", EM_ERAVM)
203203
// EraVM local end
204+
// EVM local begin
205+
.Case("evm", EM_EVM)
206+
// EVM local end
204207
.Default(EM_NONE);
205208
}
206209

@@ -571,6 +574,10 @@ StringRef ELF::convertEMachineToArchName(uint16_t EMachine) {
571574
case EM_ERAVM:
572575
return "eravm";
573576
// EraVM local end
577+
// EVM local begin
578+
case EM_EVM:
579+
return "evm";
580+
// EVM local end
574581
default:
575582
return "None";
576583
}

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,14 +1096,7 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
10961096
std::map<const MCSymbol *, std::vector<const MCSectionELF *>> GroupMembers;
10971097

10981098
// Write out the ELF header ...
1099-
// EVM local begin
1100-
// HACK!!! For EVM target we don't need the whole EFL file,
1101-
// but just its .text section. The natural way would be to extract
1102-
// it using objdump utility, but design of our FE doesn't admit
1103-
// usage of any other tool besides the BE itslef.
1104-
if (!Ctx.getTargetTriple().isEVM())
1105-
writeHeader(Asm);
1106-
// EVM local end
1099+
writeHeader(Asm);
11071100

11081101
// ... then the sections ...
11091102
SectionOffsetsTy SectionOffsets;
@@ -1120,14 +1113,6 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
11201113
const uint64_t SecStart = align(Section.getAlign());
11211114

11221115
const MCSymbolELF *SignatureSymbol = Section.getGroup();
1123-
// EVM local begin
1124-
if (Ctx.getTargetTriple().isEVM()) {
1125-
if (Section.getName() == ".text")
1126-
writeSectionData(Asm, Section, Layout);
1127-
continue;
1128-
}
1129-
// EVM local end
1130-
11311116
writeSectionData(Asm, Section, Layout);
11321117

11331118
uint64_t SecEnd = W.OS.tell();
@@ -1160,11 +1145,6 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
11601145
OWriter.TargetObjectWriter->addTargetSectionFlags(Ctx, Section);
11611146
}
11621147

1163-
// EVM local begin
1164-
if (Ctx.getTargetTriple().isEVM())
1165-
return W.OS.tell() - StartOffset;
1166-
// EVM local end
1167-
11681148
for (MCSectionELF *Group : Groups) {
11691149
// Remember the offset into the file for this section.
11701150
const uint64_t SecStart = align(Group->getAlign());

llvm/lib/MC/MCExpr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) {
388388
case VK_VE_TLS_GD_LO32: return "tls_gd_lo";
389389
case VK_VE_TPOFF_HI32: return "tpoff_hi";
390390
case VK_VE_TPOFF_LO32: return "tpoff_lo";
391+
// EVM local begin
392+
case VK_EVM_DATA:
393+
return "evm_data";
394+
// EVM local end
391395
}
392396
llvm_unreachable("Invalid variant kind");
393397
}
@@ -532,6 +536,9 @@ MCSymbolRefExpr::getVariantKindForName(StringRef Name) {
532536
.Case("tls_gd_lo", VK_VE_TLS_GD_LO32)
533537
.Case("tpoff_hi", VK_VE_TPOFF_HI32)
534538
.Case("tpoff_lo", VK_VE_TPOFF_LO32)
539+
// EVM local begin
540+
.Case("evm_data", VK_EVM_DATA)
541+
// EVM local end
535542
.Default(VK_Invalid);
536543
}
537544

llvm/lib/MC/MCObjectFileInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
386386

387387
TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
388388
ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
389+
// EVM local begin
390+
if (T.getArch() == Triple::evm)
391+
TextSection->setAlignment(Align(1));
392+
// EVM local end
389393

390394
DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
391395
ELF::SHF_WRITE | ELF::SHF_ALLOC);

llvm/lib/Object/ELF.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,20 @@ StringRef llvm::object::getELFRelocationTypeName(uint32_t Machine,
185185
case ELF::EM_ERAVM:
186186
switch (Type) {
187187
#include "llvm/BinaryFormat/ELFRelocs/EraVM.def"
188-
default:
188+
default:
189189
break;
190190
}
191191
break;
192192
// EraVM local end
193+
// EVM local begin
194+
case ELF::EM_EVM:
195+
switch (Type) {
196+
#include "llvm/BinaryFormat/ELFRelocs/EVM.def"
197+
default:
198+
break;
199+
}
200+
break;
201+
// EVM local end
193202
default:
194203
break;
195204
}
@@ -242,6 +251,10 @@ uint32_t llvm::object::getELFRelativeRelocationType(uint32_t Machine) {
242251
break;
243252
case ELF::EM_LOONGARCH:
244253
return ELF::R_LARCH_RELATIVE;
254+
// EVM local begin
255+
case ELF::EM_EVM:
256+
break;
257+
// EVM local end
245258
default:
246259
break;
247260
}

0 commit comments

Comments
 (0)