What is an LLVM virtual section in the context of object files?
Asked Answered
H

1

11

Whilst looking at a bugfix in the LLVM source code, I came across the term, "virtual section" and wondered what it meant.

I tried Googling a few different terms and browsing the source code further, but all I managed to find was that the implementations for each object file format's isSectionVirtual member function appear to express that a section is virtual if it has no contents (such as a .bss section, but the source code clearly expresses that these are two different concepts). The implementation varies depending on the specific object format involved.

I am fairly new to understanding the innards of object files, so I am not sure if this is an LLVM thing or a more general concept present outside of LLVM.

Could somebody please tell me what a virtual section is in an object file?

Habiliment answered 15/10, 2015 at 9:44 Comment(0)
D
1

According to comments in LLVM source code, the "virtual section" is a section which doesn't have any data in object file. (PE/COFF specification doesn't have such term, so it's probably used only in LLVM).

The .bss section has only uninitialized data, so it shouldn't have any data in object file (although theoretically it can). So the .bss section should be "virtual", and there is no need to have the following code in LLVM:

if (Sec.isBSS() || Sec.isVirtual())

But the thing is that LLVM doesn't support "virtual" sections in Mach-O files (or maybe Mach-O files cannot have them)

bool MachOObjectFile::isSectionVirtual(DataRefImpl Sec) const {
  // FIXME: Unimplemented.
  return false;
}

Hence LLVM has separate checks for isBSS and isVirtual.

A BSS section is:

  • readable
  • writeable
  • non-executable
  • uninitialised data

A virtual section might have different properties and use cases, such as writeable + executable, or non-readable (alignment) sections which are not BSS (note that writeable + executable sections are insecure, and "alignment" sections are useful only for some code protection (anti-dump) tricks).

So every BSS section is a virtual section, but not every virtual section is a BSS section.

Dainedainty answered 30/10, 2015 at 19:47 Comment(2)
Surely the separate checks indicate that these are in fact different concepts? Otherwise, there'd just be isBSS and isVirtual wouldn't need to exist. Thanks for your input regardless!Habiliment
Thanks, that's much better!Habiliment

© 2022 - 2024 — McMap. All rights reserved.