mirror of
https://github.com/rui314/mold.git
synced 2024-12-28 02:44:48 +03:00
temporary
This commit is contained in:
parent
13e3ab4eba
commit
f93c204dfa
30
common.h
Normal file
30
common.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#define SECTOR_SIZE 512
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
|
||||
typedef int8_t i8;
|
||||
typedef int16_t i16;
|
||||
typedef int32_t i32;
|
||||
typedef int64_t i64;
|
||||
|
||||
using llvm::ArrayRef;
|
||||
using llvm::ErrorOr;
|
||||
using llvm::Error;
|
||||
using llvm::Expected;
|
||||
using llvm::MemoryBufferRef;
|
||||
using llvm::SmallVector;
|
||||
using llvm::StringRef;
|
||||
using llvm::Twine;
|
||||
using llvm::object::ELF64LE;
|
||||
using llvm::object::ELFFile;
|
||||
|
||||
class Symbol;
|
||||
class InputSection;
|
||||
class ObjectFile;
|
||||
class OutputSection;
|
14
main.cc
14
main.cc
@ -84,15 +84,21 @@ static std::vector<MemoryBufferRef> get_archive_members(MemoryBufferRef mb) {
|
||||
}
|
||||
|
||||
static void read_file(std::vector<ObjectFile *> &files, StringRef path) {
|
||||
MemoryBufferRef mb = readFile(path);
|
||||
auto mb_or_err = MemoryBuffer::getFile(path, -1, false);
|
||||
if (auto ec = mb_or_err.getError())
|
||||
error("cannot open " + path + ": " + ec.message());
|
||||
|
||||
switch (identify_magic(mb.getBuffer())) {
|
||||
std::unique_ptr<MemoryBuffer> &mb = *mb_or_err;
|
||||
MemoryBufferRef mbref = mb->getMemBufferRef();
|
||||
mb.release();
|
||||
|
||||
switch (identify_magic(mbref.getBuffer())) {
|
||||
case file_magic::archive:
|
||||
for (MemoryBufferRef member : get_archive_members(mb))
|
||||
for (MemoryBufferRef member : get_archive_members(mbref))
|
||||
files.push_back(new ObjectFile(member, path));
|
||||
break;
|
||||
case file_magic::elf_relocatable:
|
||||
files.push_back(new ObjectFile(mb, ""));
|
||||
files.push_back(new ObjectFile(mbref, ""));
|
||||
break;
|
||||
default:
|
||||
error(path + ": unknown file type");
|
||||
|
35
mold.h
35
mold.h
@ -43,34 +43,7 @@
|
||||
#include <valarray>
|
||||
#include <xmmintrin.h>
|
||||
|
||||
#define SECTOR_SIZE 512
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
|
||||
typedef int8_t i8;
|
||||
typedef int16_t i16;
|
||||
typedef int32_t i32;
|
||||
typedef int64_t i64;
|
||||
|
||||
using llvm::ArrayRef;
|
||||
using llvm::ErrorOr;
|
||||
using llvm::Error;
|
||||
using llvm::Expected;
|
||||
using llvm::MemoryBufferRef;
|
||||
using llvm::SmallVector;
|
||||
using llvm::StringRef;
|
||||
using llvm::Twine;
|
||||
using llvm::object::ELF64LE;
|
||||
using llvm::object::ELFFile;
|
||||
|
||||
class Symbol;
|
||||
class InputSection;
|
||||
class ObjectFile;
|
||||
class OutputSection;
|
||||
#include "common.h"
|
||||
|
||||
struct Config {
|
||||
StringRef output;
|
||||
@ -592,12 +565,6 @@ private:
|
||||
|
||||
void print_map(ArrayRef<ObjectFile *> files, ArrayRef<OutputChunk *> output_sections);
|
||||
|
||||
//
|
||||
// main.cc
|
||||
//
|
||||
|
||||
MemoryBufferRef readFile(StringRef path);
|
||||
|
||||
//
|
||||
// Other
|
||||
//
|
||||
|
@ -7,17 +7,6 @@ ObjectFile::ObjectFile(MemoryBufferRef mb, StringRef archive_name)
|
||||
: mb(mb), name(mb.getBufferIdentifier()), archive_name(archive_name),
|
||||
obj(check(ELFFile<ELF64LE>::create(mb.getBuffer()))) {}
|
||||
|
||||
MemoryBufferRef readFile(StringRef path) {
|
||||
auto mbOrErr = MemoryBuffer::getFile(path, -1, false);
|
||||
if (auto ec = mbOrErr.getError())
|
||||
error("cannot open " + path + ": " + ec.message());
|
||||
|
||||
std::unique_ptr<MemoryBuffer> &mb = *mbOrErr;
|
||||
MemoryBufferRef mbref = mb->getMemBufferRef();
|
||||
mb.release();
|
||||
return mbref;
|
||||
}
|
||||
|
||||
static const ELF64LE::Shdr
|
||||
*findSection(ArrayRef<ELF64LE::Shdr> sections, u32 type) {
|
||||
for (const ELF64LE::Shdr &sec : sections)
|
||||
|
Loading…
Reference in New Issue
Block a user