xref: /freebsd/contrib/llvm-project/lld/ELF/Writer.h (revision 85868e8a1daeaae7a0e48effb2ea2310ae3b02c6)
10b57cec5SDimitry Andric //===- Writer.h -------------------------------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #ifndef LLD_ELF_WRITER_H
100b57cec5SDimitry Andric #define LLD_ELF_WRITER_H
110b57cec5SDimitry Andric 
12*85868e8aSDimitry Andric #include "Config.h"
130b57cec5SDimitry Andric #include "llvm/ADT/ArrayRef.h"
140b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h"
150b57cec5SDimitry Andric #include <cstdint>
160b57cec5SDimitry Andric #include <memory>
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric namespace lld {
190b57cec5SDimitry Andric namespace elf {
200b57cec5SDimitry Andric class InputFile;
210b57cec5SDimitry Andric class OutputSection;
220b57cec5SDimitry Andric class InputSectionBase;
23*85868e8aSDimitry Andric void copySectionsIntoPartitions();
24*85868e8aSDimitry Andric template <class ELFT> void createSyntheticSections();
25*85868e8aSDimitry Andric void combineEhSections();
260b57cec5SDimitry Andric template <class ELFT> void writeResult();
270b57cec5SDimitry Andric 
280b57cec5SDimitry Andric // This describes a program header entry.
290b57cec5SDimitry Andric // Each contains type, access flags and range of output sections that will be
300b57cec5SDimitry Andric // placed in it.
310b57cec5SDimitry Andric struct PhdrEntry {
32*85868e8aSDimitry Andric   PhdrEntry(unsigned type, unsigned flags)
33*85868e8aSDimitry Andric       : p_align(type == llvm::ELF::PT_LOAD ? config->maxPageSize : 0),
34*85868e8aSDimitry Andric         p_type(type), p_flags(flags) {}
350b57cec5SDimitry Andric   void add(OutputSection *sec);
360b57cec5SDimitry Andric 
370b57cec5SDimitry Andric   uint64_t p_paddr = 0;
380b57cec5SDimitry Andric   uint64_t p_vaddr = 0;
390b57cec5SDimitry Andric   uint64_t p_memsz = 0;
400b57cec5SDimitry Andric   uint64_t p_filesz = 0;
410b57cec5SDimitry Andric   uint64_t p_offset = 0;
420b57cec5SDimitry Andric   uint32_t p_align = 0;
430b57cec5SDimitry Andric   uint32_t p_type = 0;
440b57cec5SDimitry Andric   uint32_t p_flags = 0;
450b57cec5SDimitry Andric 
460b57cec5SDimitry Andric   OutputSection *firstSec = nullptr;
470b57cec5SDimitry Andric   OutputSection *lastSec = nullptr;
480b57cec5SDimitry Andric   bool hasLMA = false;
490b57cec5SDimitry Andric 
500b57cec5SDimitry Andric   uint64_t lmaOffset = 0;
510b57cec5SDimitry Andric };
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric void addReservedSymbols();
540b57cec5SDimitry Andric llvm::StringRef getOutputSectionName(const InputSectionBase *s);
550b57cec5SDimitry Andric 
560b57cec5SDimitry Andric template <class ELFT> uint32_t calcMipsEFlags();
570b57cec5SDimitry Andric 
580b57cec5SDimitry Andric uint8_t getMipsFpAbiFlag(uint8_t oldFlag, uint8_t newFlag,
590b57cec5SDimitry Andric                          llvm::StringRef fileName);
600b57cec5SDimitry Andric 
610b57cec5SDimitry Andric bool isMipsN32Abi(const InputFile *f);
620b57cec5SDimitry Andric bool isMicroMips();
630b57cec5SDimitry Andric bool isMipsR6();
640b57cec5SDimitry Andric } // namespace elf
650b57cec5SDimitry Andric } // namespace lld
660b57cec5SDimitry Andric 
670b57cec5SDimitry Andric #endif
68