mirror of
https://github.com/rui314/mold.git
synced 2024-12-28 02:44:48 +03:00
temporary
This commit is contained in:
parent
7fbad02cd4
commit
5ccf327790
3
Makefile
3
Makefile
@ -2,13 +2,14 @@ CC=clang
|
|||||||
CXX=clang++
|
CXX=clang++
|
||||||
LLVM_CONFIG=llvm-project/build/bin/llvm-config
|
LLVM_CONFIG=llvm-project/build/bin/llvm-config
|
||||||
LLVM_TBLGEN=llvm-project/build/bin/llvm-tblgen
|
LLVM_TBLGEN=llvm-project/build/bin/llvm-tblgen
|
||||||
|
LLVM_LIBS=$(wildcard llvm-project/build/lib/libLLVM*.a)
|
||||||
|
|
||||||
CURRENT_DIR=$(shell pwd)
|
CURRENT_DIR=$(shell pwd)
|
||||||
TBB_LIBDIR=$(wildcard $(CURRENT_DIR)/oneTBB/build/linux_intel64_*_release/)
|
TBB_LIBDIR=$(wildcard $(CURRENT_DIR)/oneTBB/build/linux_intel64_*_release/)
|
||||||
|
|
||||||
CPPFLAGS=-g $(shell $(LLVM_CONFIG) --cxxflags) -IoneTBB/include -pthread
|
CPPFLAGS=-g $(shell $(LLVM_CONFIG) --cxxflags) -IoneTBB/include -pthread
|
||||||
LDFLAGS=$(shell $(LLVM_CONFIG) --ldflags) -L$(TBB_LIBDIR) -Wl,-rpath=$(TBB_LIBDIR)
|
LDFLAGS=$(shell $(LLVM_CONFIG) --ldflags) -L$(TBB_LIBDIR) -Wl,-rpath=$(TBB_LIBDIR)
|
||||||
LIBS=-pthread -lLLVMSupport -lLLVMObject -lLLVMOption -lLLVMBinaryFormat -lcurses -ltbb
|
LIBS=-pthread -ltbb -lcurses -Wl,--start-group $(LLVM_LIBS) -Wl,--end-group
|
||||||
OBJS=main.o writer.o input_files.o symtab.o
|
OBJS=main.o writer.o input_files.o symtab.o
|
||||||
|
|
||||||
chibild: $(OBJS)
|
chibild: $(OBJS)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/ADT/Twine.h"
|
#include "llvm/ADT/Twine.h"
|
||||||
#include "llvm/BinaryFormat/Magic.h"
|
#include "llvm/BinaryFormat/Magic.h"
|
||||||
|
#include "llvm/Object/Archive.h"
|
||||||
#include "llvm/Object/ELF.h"
|
#include "llvm/Object/ELF.h"
|
||||||
#include "llvm/Object/ELFTypes.h"
|
#include "llvm/Object/ELFTypes.h"
|
||||||
#include "llvm/Support/Error.h"
|
#include "llvm/Support/Error.h"
|
||||||
@ -16,6 +17,7 @@
|
|||||||
|
|
||||||
using llvm::ArrayRef;
|
using llvm::ArrayRef;
|
||||||
using llvm::ErrorOr;
|
using llvm::ErrorOr;
|
||||||
|
using llvm::Error;
|
||||||
using llvm::Expected;
|
using llvm::Expected;
|
||||||
using llvm::MemoryBufferRef;
|
using llvm::MemoryBufferRef;
|
||||||
using llvm::SmallVector;
|
using llvm::SmallVector;
|
||||||
|
@ -61,7 +61,7 @@ void ObjectFile::register_defined_symbols() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
symbol_table.add(sym.name, sym);
|
symbol_table.add(sym.name, sym);
|
||||||
llvm::errs() << symbol_table.get(sym.name).name << "\n";
|
llvm::errs() << "x=" << symbol_table.get(sym.name)->name << "\n";
|
||||||
symbols.push_back(&sym);
|
symbols.push_back(&sym);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
56
main.cc
56
main.cc
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
using llvm::file_magic;
|
||||||
|
using llvm::object::Archive;
|
||||||
using llvm::opt::InputArgList;
|
using llvm::opt::InputArgList;
|
||||||
|
|
||||||
Config config;
|
Config config;
|
||||||
@ -58,6 +60,45 @@ InputArgList MyOptTable::parse(int argc, char **argv) {
|
|||||||
// Main
|
// Main
|
||||||
//
|
//
|
||||||
|
|
||||||
|
static std::vector<MemoryBufferRef> getArchiveMembers(MemoryBufferRef mb) {
|
||||||
|
std::unique_ptr<Archive> file =
|
||||||
|
CHECK(Archive::create(mb), mb.getBufferIdentifier() + ": failed to parse archive");
|
||||||
|
|
||||||
|
std::vector<MemoryBufferRef> vec;
|
||||||
|
|
||||||
|
Error err = Error::success();
|
||||||
|
|
||||||
|
for (const Archive::Child &c : file->children(err)) {
|
||||||
|
MemoryBufferRef mbref =
|
||||||
|
CHECK(c.getMemoryBufferRef(),
|
||||||
|
mb.getBufferIdentifier() +
|
||||||
|
": could not get the buffer for a child of the archive");
|
||||||
|
vec.push_back(mbref);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err)
|
||||||
|
error(mb.getBufferIdentifier() + ": Archive::children failed: " +
|
||||||
|
toString(std::move(err)));
|
||||||
|
|
||||||
|
return vec;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void add_file(std::vector<ObjectFile *> &files, StringRef path) {
|
||||||
|
MemoryBufferRef mb = readFile(path);
|
||||||
|
|
||||||
|
switch (identify_magic(mb.getBuffer())) {
|
||||||
|
case file_magic::archive:
|
||||||
|
for (MemoryBufferRef member : getArchiveMembers(mb))
|
||||||
|
files.push_back(new ObjectFile(member));
|
||||||
|
break;
|
||||||
|
case file_magic::elf_relocatable:
|
||||||
|
files.push_back(new ObjectFile(mb));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error(path + ": unknown file type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
MyOptTable opt_table;
|
MyOptTable opt_table;
|
||||||
InputArgList args = opt_table.parse(argc - 1, argv + 1);
|
InputArgList args = opt_table.parse(argc - 1, argv + 1);
|
||||||
@ -69,19 +110,16 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
std::vector<ObjectFile *> files;
|
std::vector<ObjectFile *> files;
|
||||||
|
|
||||||
for (auto *arg : args) {
|
for (auto *arg : args)
|
||||||
switch (arg->getOption().getID()) {
|
if (arg->getOption().getID() == OPT_INPUT)
|
||||||
case OPT_INPUT: {
|
add_file(files, arg->getValue());
|
||||||
MemoryBufferRef mb = readFile(arg->getValue());
|
|
||||||
files.push_back(new ObjectFile(mb));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ObjectFile *file : files)
|
for (ObjectFile *file : files)
|
||||||
file->parse();
|
file->parse();
|
||||||
|
|
||||||
|
for (ObjectFile *file : files)
|
||||||
|
file->register_defined_symbols();
|
||||||
|
|
||||||
write();
|
write();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user