Difference between revisions of "NaplesPU LLD Linker"
(→linker) |
|||
Line 72: | Line 72: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | |||
== elf2hex == | == elf2hex == |
Revision as of 17:05, 28 May 2018
When adding a new target architecture to llvm, some changes are required to the tools located in the llvm/tools folder.
Contents
llvm-objdump
This is the llvm object file dumper. The full documentation for llvm-objdump is maintained as a Texinfo manual. If the info and llvm-objdump programs are properly installed, the command
info llvm-objdump
should give you access to the complete manual.
In order to be properly used with the NuPlus architecture the following change is required.
template <class ELFT>
static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
const RelocationRef &RelRef,
SmallVectorImpl<char> &Result) {
...
switch (EF.getHeader()->e_machine) {
...
case ELF::EM_NUPLUS:
res = Target;
break;
llvm-readobj
The llvm-readobj tool displays low-level format-specific information about one or more object files. In order to be properly used with the NuPlus architecture the following change is required.
static const EnumEntry<unsigned> ElfMachineType[] = {
...
ENUM_ENT(EM_NUPLUS, "EM_NUPLUS")
linker
mclinker is the linker used with the LLVM ver. 3.9. However, it is not under active development so we must migrate towards LLD.
The linker main purpose is to link object files in order to generate an executable file. It must resolve symbol names and relocations in order to produce a proper executable.
The nu+ version of mclinker is located in "compiler/tools". The aspects related to nu+ are in the "NuPlus" folder at the "mclinker/lib/Target" subdirectory.
The main aspects that were implemented are the relocations and the scratchpad symbols resolution. The compiler is responsible of emitting these symbols, while the linker must recognize and resolve them by substituting with the correct offset. This is done through a different functions defined in the NuPlusRelocator class. The symbol-function binding is done in the NuPlusRelocationFunctions.h file.
To correctly link the different sections, it is also created a linker script. It is located in "misc/lnkrscrpt.ld". Other then instruct the linker on where the different sections must be located, it also defines the stack starting address for each core thread. The stacks are defined by a starting address and their dimensions. In the following, we illustrate the used link script and the memory layout. By default, each stack can own 16KB of data and all stacks are located sequentially in the memory starting at address 0x080000. The memory area between 0x000000-0x00037F is used to store input and output data through/from nu+, such as the kernel arguments. At 0x000380-0x0003FF, we have the interrupt vector jump table, i.e. jump instructions to the different ISRs. Starting at 0x000400, we have the crt0 startup routines followed by the different text and data sections.
stacks_dim = 4K;
stacks_base = 0x80000;
__stack0_top__ = stacks_base;
__stack1_top__ = __stack0_top__ + stacks_dim;
__stack2_top__ = __stack1_top__ + stacks_dim;
__stack3_top__ = __stack2_top__ + stacks_dim;
__stack4_top__ = __stack3_top__ + stacks_dim;
__stack5_top__ = __stack4_top__ + stacks_dim;
__stack6_top__ = __stack5_top__ + stacks_dim;
__stack7_top__ = __stack6_top__ + stacks_dim;
SECTIONS
{
. = 0x00000400;
.text.vectors : { ../..//libs/vectors.o(.text)}
.text.start : { ../..//libs/crt0.o(.text)}
.text : { *(.text) }
.data : { *(.data) }
. = ALIGN(64);
scratchpad : { *(scratchpad) }
.bss : { *(.bss) }
}
elf2hex
The elf2hex tool (located in "/compiler/tools/elf2hex/elf2hex.cpp") takes the elf executable and converts it in hex format. It just takes the data and instructions from the elf file and print it to the output file. The file generated can be used as input to EmuPlus. However, the file requires some other transformations in order to be loaded to the real machine. The 512_hex python program ("/misc/512_hex.py") is responsible of execute these transformations.
lldb
TBD