Skip to content

Conversation

@quic-seaswara
Copy link
Contributor

This prints memory allocated by linker core data structures with a count of how many and total bytes used.

This will be followed up by improvements to report virtual memory / resident memory size.

Resolves #606

This prints memory allocated by linker core data structures
with a count of how many and total bytes used.

This will be followed up by improvements to report
virtual memory / resident memory size.

Resolves #606

Signed-off-by: Shankar Easwaran <[email protected]>
*/
class GeneralOptions {
public:
static std::string getTypeName() { return "GeneralOptions"; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please return std::string_view / llvm::StringRef / const char * instead of std::string as these are more memory efficient?

// --emit-memory-report <file>
std::string getMemoryReportFile() const { return MemoryReportFile; }

void setMemoryReportFile(std::string F) { MemoryReportFile = F; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should try to use llvm::StringRef / std::string_view wherever we can as they avoid copying strings. What do you think about it?

Suggested change
void setMemoryReportFile(std::string F) { MemoryReportFile = F; }
void setMemoryReportFile(llvm::StringRef F) { MemoryReportFile = F; }

void setPrintMemoryReport() { PrintMemoryReport = true; }

// --emit-memory-report <file>
std::string getMemoryReportFile() const { return MemoryReportFile; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string getMemoryReportFile() const { return MemoryReportFile; }
llvm::StringRef getMemoryReportFile() const { return MemoryReportFile; }

std::string TarFile; // --reproduce output tarfile name
std::string TimingStatsFile;
std::string TimingStatsFile; // --emit-timing-stats
std::string MemoryReportFile; // --emit-memory-report
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use one option std::optional<MemoryReportFile> instead of using two options PrintMemoryReport and MemoryReportFile?


// Use this arena if your object has a destructor.
// Your destructor will be invoked from freeArena().
template <typename T, typename... U> T *make(U &&...Args) {
Copy link
Member

@partaror partaror Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding the below macro for make (and slightly modifying eld::make definition) and directly using the type name supplied by the macro user to initialize the TypeName property of SpecificAlloc? I believe this will make the design significantly more maintainable and scalable.

#define MAKE(Type, ...) \
  eld::make<Type>(#Type, __VA_ARGS__);

template<typename T, typename... U> T *make(llvm::StringRef TypeName, U &&... Args) {
  return ArenaForType<T>::create(TypeName, std::forward<T>(Args)...);
}

Now ArenaForType can directly use TypeName to initialize SpecificAlloc.

Copy link
Contributor Author

@quic-seaswara quic-seaswara Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like this way better, though this will need every make(X) to be changed to make(T, X)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even currently, all make calls are of the form: make<T>(X). We still have T in the make calls :).

bool GnuLdDriver::emitMemoryReport() const {
if (!Config.options().showMemoryReport())
return true;
std::string File = Config.options().getMemoryReportFile();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string File = Config.options().getMemoryReportFile();
llvm::StringRef File = Config.options().getMemoryReportFile();

*/
class BranchIsland {
public:
static std::string getTypeName() { return "BranchIsland"; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we use macros to get these? Adding this to every single type feels needlessly complex and hard to scale.

Copy link
Contributor Author

@quic-seaswara quic-seaswara Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I think that is much better. Let me explore

return "parsing_failed";
start += strlen("parseTypeNameFromSignature<");

// MSVC might add "class ", "struct ", etc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this extra complexity for mscv?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

void setTimingStatsFile(std::string StatsFile) {
TimingStatsFile = StatsFile;
}
//--------------------Memory Report--------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this feature useful to anyone other than an eld developer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only eld developer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make this option hidden if that is what you were hinting at.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emit Memory Utilization Reports for Linker Data Structures

4 participants