Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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: 7 additions & 3 deletions llvm/lib/ObjectYAML/ELFEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1550,18 +1550,22 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
return;

for (const auto &[Idx, E] : llvm::enumerate(*Section.Entries)) {
unsigned Size = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The size setting code in this loop could be dramatically simplified for now, now that we're using fixed size entries. Outside the loop, you could just do something like:

SHeader.sh_entsize = 9 + sizeof(uintX_t);
SHeader.sh_size = Section.Entries->size() * SHeader.sh_entsize;

if (Section.Type == llvm::ELF::SHT_LLVM_FUNC_MAP) {
if (E.Version > 1)
WithColor::warning() << "unsupported SHT_LLVM_FUNC_MAP version: "
<< static_cast<int>(E.Version)
<< "; encoding using the most recent version";
CBA.write(E.Version);
SHeader.sh_size += 1;
Size += 1;
}
CBA.write<uintX_t>(E.Address, ELFT::Endianness);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Correct me if I'm wrong, but shouldn't this be using the Elf_Addr type, since it's representing an address? They might amount to the same thing, but it conveys the meaning better. (NB: I haven't tested it, so this might not work as desired)

Suggested change
CBA.write<uintX_t>(E.Address, ELFT::Endianness);
CBA.write<ELFT::Elf_Addr>(E.Address, ELFT::Endianness);

SHeader.sh_size += sizeof(uintX_t);
Size += sizeof(uintX_t);
CBA.write<uint64_t>(E.DynamicInstCount, ELFT::Endianness);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if the DynamicInstCount should be architecture-dependent type, so that on 32-bit architectures, it only takes up 4 bytes? There's probably an argument actually that it should always just be 4 bytes, since you'd be hard pressed to need more than what 4 bytes can represent in instruction counts.

SHeader.sh_size += 8;
Size += 8;

SHeader.sh_size += Size;
SHeader.sh_entsize = Size;
}
}

Expand Down
4 changes: 4 additions & 0 deletions llvm/test/tools/obj2yaml/ELF/func-map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# VALID-NEXT: Sections:
# VALID-NEXT: - Name: .llvm_func_map
# VALID-NEXT: Type: SHT_LLVM_FUNC_MAP
# VALID-NEXT: EntSize: 0x11
# VALID-NEXT: Entries:
# VALID-NEXT: - Version: 1
## The 'Address' field is omitted when it's zero.
Expand Down Expand Up @@ -82,12 +83,14 @@ Sections:
# MULTI-NEXT: Sections:
# MULTI-NEXT: - Name: .llvm_func_map
# MULTI-NEXT: Type: SHT_LLVM_FUNC_MAP
# MULTI-NEXT: EntSize: 0x11
# MULTI-NEXT: Entries:
# MULTI-NEXT: - Version: 1
# MULTI-NEXT: Address: 0x2
# MULTI-NEXT: DynInstCnt: 3
# MULTI-NEXT: - Name: '.llvm_func_map (1)'
# MULTI-NEXT: Type: SHT_LLVM_FUNC_MAP
# MULTI-NEXT: EntSize: 0x11
# MULTI-NEXT: Entries:
# MULTI-NEXT: - Version: 1
# MULTI-NEXT: Address: 0xA
Expand Down Expand Up @@ -127,4 +130,5 @@ Sections:
# INVALID-NEXT: Sections:
# INVALID-NEXT: - Name: .llvm_func_map
# INVALID-NEXT: Type: SHT_LLVM_FUNC_MAP
# INVALID-NEXT: EntSize: 0x11
# TRUNCATED-NEXT: Content: '{{([[:xdigit:]]{16})}}'{{$}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd be tempted to explicitly check the expected 8 bytes here, to show that it's not producing garbage here.