Skip to content

Commit

Permalink
Report an error if a mergeable/merged section is too large
Browse files Browse the repository at this point in the history
We use u32 as an index into mergeable/merged sections, so we cannot
handle extremely large sections.
  • Loading branch information
rui314 committed Apr 28, 2024
1 parent 31969a2 commit 6b70e02
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,6 @@ inline bool remove_prefix(std::string_view &s, std::string_view prefix) {
return false;
}

//
// Concurrent Map
//

static inline void pause() {
#if defined(__x86_64__)
asm volatile("pause");
Expand All @@ -532,6 +528,10 @@ static inline void pause() {
#endif
}

//
// Concurrent Map
//

// This is an implementation of a fast concurrent hash map. Unlike
// ordinary hash tables, this impl just aborts if it becomes full.
// So you need to give a correct estimation of the final size before
Expand Down
3 changes: 3 additions & 0 deletions elf/input-files.cc
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,9 @@ split_section(Context<E> &ctx, InputSection<E> &sec) {
std::string_view data = sec.contents;
m->contents = sec.contents;

if (data.size() > UINT32_MAX)
Fatal(ctx) << sec << ": mergeable section too large";

// Split sections
if (shdr.sh_flags & SHF_STRINGS) {
for (i64 pos = 0; pos < data.size();) {
Expand Down
3 changes: 3 additions & 0 deletions elf/output-chunks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,9 @@ void MergedSection<E>::assign_offsets(Context<E> &ctx) {

this->shdr.sh_size = shard_offsets[map.NUM_SHARDS];
this->shdr.sh_addralign = alignment;

if (this->shdr.sh_size > UINT32_MAX)
Fatal(ctx) << this->name << ": output section too large";
}

template <typename E>
Expand Down

0 comments on commit 6b70e02

Please sign in to comment.