Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/eld/Config/GeneralOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,15 @@ class GeneralOptions {
return ArchiveMemberReportFile;
}

// --emit-load-info-json
void setEmitLoadInfoJsonFile(llvm::StringRef File) {
EmitLoadInfoJsonFile = File.str();
}

const std::optional<std::string> &getEmitLoadInfoJsonFile() const {
return EmitLoadInfoJsonFile;
}

// --ld-generated-unwind-info
void setGenUnwindInfo(bool PEnable = true) { BGenUnwindInfo = PEnable; }

Expand Down Expand Up @@ -1426,6 +1435,7 @@ class GeneralOptions {
std::string LinkLaunchDirectory;
bool ShowRMSectNameInDiag = false;
bool UseDefaultPlugins = true;
std::optional<std::string> EmitLoadInfoJsonFile;
};

} // namespace eld
Expand Down
2 changes: 1 addition & 1 deletion include/eld/Diagnostics/DiagCommonKinds.inc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ DIAG(plugin_crash, DiagnosticEngine::Fatal,
DIAG(unable_to_create_temporary_file, DiagnosticEngine::Fatal,
"Unable to create temporary file %0")
DIAG(unable_to_write_json_file, DiagnosticEngine::Error,
"Unable to write JSON file %0 due to error %1")
"Unable to write file %0 due to %1")
DIAG(unsupported_linker_flavor, DiagnosticEngine::Error,
"Unsupported linker flavor %0")
DIAG(unable_to_compress, DiagnosticEngine::Fatal, "Unable to compress %0")
Expand Down
6 changes: 6 additions & 0 deletions include/eld/Driver/GnuLinkerOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,12 @@ defm ArchiveMemberReportFile
MetaVarName<"<filename>">,
Group<grp_miscfeatures>;

defm EmitLoadInfoJson
: smDashWithOpt<"emit-load-info-json", "EmitLoadInfoJson",
"Emit JSON report containing information about all input files">,
MetaVarName<"<filename>">,
Group<grp_miscfeatures>;

//===----------------------------------------------------------------------===//
/// Help!
//===----------------------------------------------------------------------===//
Expand Down
13 changes: 13 additions & 0 deletions include/eld/Input/Input.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ class Input {
static void cacheMemoryAreaForPath(const std::string &Filepath,
MemoryArea *Area);

/// Set the ordinal value that marks the end of internal inputs.
/// This should be called after all internal inputs are created.
static void setInternalInputOrderEnd(uint32_t OrderEnd) {
InternalInputOrderEnd = OrderEnd;
}

/// Get the ordinal value that marks the end of internal inputs.
/// User input ordinals start from this value.
static uint32_t getInternalInputOrderEnd() { return InternalInputOrderEnd; }

private:
// Check if a path is valid and emit any errors
bool isPathValid(const std::string &Path) const;
Expand Down Expand Up @@ -215,6 +225,9 @@ class Input {
/// the link command-line.
static std::unordered_map<std::string, MemoryArea *>
ResolvedPathToMemoryAreaMap;

/// The ordinal value marking the end of internal inputs.
static uint32_t InternalInputOrderEnd;
};

} // namespace eld
Expand Down
53 changes: 53 additions & 0 deletions include/eld/Object/LoadInfoReport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//===- LoadInfoReport.h---------------------------------------------------===//
// Part of the eld Project, under the BSD License
// See https://github.com/qualcomm/eld/LICENSE.txt for license information.
// SPDX-License-Identifier: BSD-3-Clause
//===----------------------------------------------------------------------===//

#ifndef ELD_OBJECT_LOADINFOREPORT_H
#define ELD_OBJECT_LOADINFOREPORT_H

#include "eld/Object/ObjectLinker.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/JSON.h"
#include <unordered_map>
#include <vector>

namespace eld {

class ArchiveFile;
class DiagnosticEngine;
class Input;
class InputAction;
class LinkerScriptFile;

class LoadInfoReport {
public:
LoadInfoReport(const ObjectLinker &ObjLinker,
const std::vector<InputAction *> &Actions,
DiagnosticEngine &DiagEngine);

bool emitLoadInfoJson(llvm::StringRef Filename);

private:
using ArchiveRecordsMapType =
std::unordered_map<ArchiveFile *,
std::vector<ObjectLinker::ArchiveMemberReportRecord>>;

ArchiveRecordsMapType buildArchiveRecordsMap();
llvm::StringRef getTypeName(InputFile::InputFileKind Kind);
llvm::StringRef getBehaviorOptionName(InputAction::InputActionKind Kind);
bool isBehaviorOption(InputAction::InputActionKind Kind);
llvm::json::Object emitInputEntry(Input *I, bool IncludeIndex);
void emitArchiveMembers(llvm::json::Object &Entry, ArchiveFile *AF);
void emitNestedInputs(llvm::json::Object &Entry, LinkerScriptFile *LSF);

const ObjectLinker &ObjLinker;
const std::vector<InputAction *> &Actions;
DiagnosticEngine &DiagEngine;
ArchiveRecordsMapType ArchiveRecordsMap;
};

} // namespace eld

#endif // ELD_OBJECT_LOADINFOREPORT_H
3 changes: 3 additions & 0 deletions lib/Core/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ bool Module::createInternalInputs() {
ResolvedResult.Info->setOutSymbol(DotSym);
setDotSymbol(DotSym);

Input::setInternalInputOrderEnd(
static_cast<uint32_t>(Module::InternalInputType::MAX));

return true;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/Input/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ llvm::hash_code Input::computeFilePathHash(llvm::StringRef FilePath) {
std::unordered_map<std::string, MemoryArea *>
Input::ResolvedPathToMemoryAreaMap;

uint32_t Input::InternalInputOrderEnd = 0;

MemoryArea *Input::getMemoryAreaForPath(const std::string &Filepath,
DiagnosticEngine *DiagEngine) {
auto Iter = ResolvedPathToMemoryAreaMap.find(Filepath);
Expand Down
28 changes: 21 additions & 7 deletions lib/LinkerWrapper/GnuLdDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "eld/LayoutMap/TextLayoutPrinter.h"
#include "eld/LayoutMap/YamlLayoutPrinter.h"
#include "eld/Object/ArchiveMemberReport.h"
#include "eld/Object/LoadInfoReport.h"
#include "eld/Support/FileSystem.h"
#include "eld/Support/MappingFileReader.h"
#include "eld/Support/MsgHandling.h"
Expand Down Expand Up @@ -62,11 +63,12 @@ using namespace eld;
static constexpr llvm::opt::OptTable::Info infoTable[] = {
#define OPTION(PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, GROUP, ALIAS, \
ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, \
HELPTEXTSFORVARIANTS, METAVAR, VALUES, SUBCOMMANDIDS_OFFSET) \
LLVM_CONSTRUCT_OPT_INFO( \
PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, GnuLdOptTable::ID, KIND, \
GnuLdOptTable::GROUP, GnuLdOptTable::ALIAS, ALIASARGS, FLAGS, \
VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, METAVAR, VALUES, SUBCOMMANDIDS_OFFSET),
HELPTEXTSFORVARIANTS, METAVAR, VALUES, SUBCOMMANDIDS_OFFSET) \
LLVM_CONSTRUCT_OPT_INFO(PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, \
GnuLdOptTable::ID, KIND, GnuLdOptTable::GROUP, \
GnuLdOptTable::ALIAS, ALIASARGS, FLAGS, VISIBILITY, \
PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, METAVAR, \
VALUES, SUBCOMMANDIDS_OFFSET),
#include "eld/Driver/GnuLinkerOptions.inc"
#undef OPTION
};
Expand Down Expand Up @@ -601,7 +603,8 @@ bool GnuLdDriver::processOptions(llvm::opt::InputArgList &Args) {
// --enable-linker-version / --disable-linker-version
if (Args.hasArg(T::enable_linker_version) &&
Args.hasArg(T::disable_linker_version)) {
errs() << "Cannot specify enable and disable LINKER_VERSION at same time!\n";
errs()
<< "Cannot specify enable and disable LINKER_VERSION at same time!\n";
return false;
}

Expand All @@ -612,7 +615,8 @@ bool GnuLdDriver::processOptions(llvm::opt::InputArgList &Args) {

if (Args.hasArg(T::disable_linker_version)) {
Config.options().setLinkerVersionDirectiveEnabled(false);
Config.addCommandLine(Table->getOptionName(T::disable_linker_version), true);
Config.addCommandLine(Table->getOptionName(T::disable_linker_version),
true);
}

bool recordCommandLine = Args.hasFlag(
Expand Down Expand Up @@ -1302,6 +1306,11 @@ bool GnuLdDriver::processOptions(llvm::opt::InputArgList &Args) {
Config.options().setArchiveMemberReportFile(A->getValue());
}

// --emit-load-info-json=<file>
if (llvm::opt::Arg *A = Args.getLastArg(T::EmitLoadInfoJson)) {
Config.options().setEmitLoadInfoJsonFile(A->getValue());
}

Config.options().setUnknownOptions(Args.getAllArgValues(T::UNKNOWN));
return true;
}
Expand Down Expand Up @@ -1991,6 +2000,11 @@ bool GnuLdDriver::doLink(llvm::opt::InputArgList &Args,
}
if (!linkStatus || Config.options().getRecordInputFiles())
handleReproduce<T>(Args, actions, true);
if (auto &LoadInfoFile = Config.options().getEmitLoadInfoJsonFile()) {
LoadInfoReport Report(*linker.getObjectLinker(), actions,
*Config.getDiagEngine());
Report.emitLoadInfoJson(LoadInfoFile.value());
}
if (auto &PluginActLog = ThisModule->getPluginActivityLog()) {
PluginActLog->print(Config.options().getPluginActivityLogFile().value());
}
Expand Down
1 change: 1 addition & 0 deletions lib/Object/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ llvm_add_library(
RuleContainer.cpp
SectionMap.cpp
ArchiveMemberReport.cpp
LoadInfoReport.cpp
DEPENDS
intrinsics_gen)

Expand Down
Loading
Loading