При компиляции объектного файла, созданного через LLVM C++ API с использованием Clang в Ubuntu (wsl), я получаю следующую ошибку
compiled.o : fatal error LNK1107: invalid or corrupt file: cannot read at 0x898
clang: error: linker command failed with exit code 1107 (use -v to see invocation)
У меня есть следующий код на моем языке (который успешно запускается, если я распечатаю модуль в IR-файл и скомпилирую его с помощью clang в исполняемый файл)
func printf(format : string, args : any...) : int
func main(argc : int) : int {
printf("number of arguments : %d\n", argc);
c = 155;
printf("check c : %d\n", c);
return 0;
}
Я использовал этот код для создания объектного файла
void Codegen::save_to_object_file(const std::string &out_path) {
// Initialize the target registry etc.
InitializeAllTargetInfos();
InitializeAllTargets();
InitializeAllTargetMCs();
InitializeAllAsmParsers();
InitializeAllAsmPrinters();
auto TargetTriple = sys::getDefaultTargetTriple();
module->setTargetTriple(TargetTriple);
std::string Error;
auto Target = TargetRegistry::lookupTarget(TargetTriple, Error);
// Print an error and exit if we couldn't find the requested target.
// This generally occurs if we've forgotten to initialise the
// TargetRegistry or we have a bogus target triple.
if (!Target) {
error(Error);
return;
}
auto CPU = "generic";
auto Features = "";
TargetOptions opt;
auto TheTargetMachine = Target->createTargetMachine(
TargetTriple, CPU, Features, opt, Reloc::PIC_);
module->setDataLayout(TheTargetMachine->createDataLayout());
std::error_code EC;
raw_fd_ostream dest(out_path, EC, sys::fs::CD_CreateAlways);
if (EC) {
error("Could not open file: " + EC.message());
return;
}
legacy::PassManager pass;
auto FileType = CodeGenFileType::CGFT_ObjectFile;
if (TheTargetMachine->addPassesToEmitFile(pass, dest, nullptr, FileType)) {
error("TheTargetMachine can't emit a file of this type");
return;
}
pass.run(*module);
dest.flush();
}
Подробнее здесь: https://stackoverflow.com/questions/781 ... bject-file
LLVM генерирует поврежденный объектный файл ⇐ C++
Программы на C++. Форум разработчиков
-
Anonymous
1710613110
Anonymous
При компиляции объектного файла, созданного через LLVM C++ API с использованием Clang в Ubuntu (wsl), я получаю следующую ошибку
compiled.o : fatal error LNK1107: invalid or corrupt file: cannot read at 0x898
clang: error: linker command failed with exit code 1107 (use -v to see invocation)
У меня есть следующий код на моем языке (который успешно запускается, если я распечатаю модуль в IR-файл и скомпилирую его с помощью clang в исполняемый файл)
func printf(format : string, args : any...) : int
func main(argc : int) : int {
printf("number of arguments : %d\n", argc);
c = 155;
printf("check c : %d\n", c);
return 0;
}
Я использовал этот код для создания объектного файла
void Codegen::save_to_object_file(const std::string &out_path) {
// Initialize the target registry etc.
InitializeAllTargetInfos();
InitializeAllTargets();
InitializeAllTargetMCs();
InitializeAllAsmParsers();
InitializeAllAsmPrinters();
auto TargetTriple = sys::getDefaultTargetTriple();
module->setTargetTriple(TargetTriple);
std::string Error;
auto Target = TargetRegistry::lookupTarget(TargetTriple, Error);
// Print an error and exit if we couldn't find the requested target.
// This generally occurs if we've forgotten to initialise the
// TargetRegistry or we have a bogus target triple.
if (!Target) {
error(Error);
return;
}
auto CPU = "generic";
auto Features = "";
TargetOptions opt;
auto TheTargetMachine = Target->createTargetMachine(
TargetTriple, CPU, Features, opt, Reloc::PIC_);
module->setDataLayout(TheTargetMachine->createDataLayout());
std::error_code EC;
raw_fd_ostream dest(out_path, EC, sys::fs::CD_CreateAlways);
if (EC) {
error("Could not open file: " + EC.message());
return;
}
legacy::PassManager pass;
auto FileType = CodeGenFileType::CGFT_ObjectFile;
if (TheTargetMachine->addPassesToEmitFile(pass, dest, nullptr, FileType)) {
error("TheTargetMachine can't emit a file of this type");
return;
}
pass.run(*module);
dest.flush();
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78172861/llvm-generating-corrupt-object-file[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия