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?
What is commonly known as the LLVM bitcode file format (also, sometimes anachronistically known as bytecode) is actually two things: a bitstream container format and an encoding of LLVM IR into the container format. The bitstream format is an abstract encoding of structured data, very similar to XML in some ways.
LLVM is an acronym that stands for low level virtual machine. It also refers to a compiling technology called the LLVM project, which is a collection of modular and reusable compiler and toolchain technologies.
The LLVM Project is a collection of modular and reusable compiler and toolchain technologies, with a primary focus on these two compilers: The LLVM back-end compiler and core libraries provide a modern source- and target-independent optimizer, along with code generation support for the RHEL CPU architectures.
The combination of Clang front-end and LLVM back-end is called Clang/LLVM or simply Clang. The name LLVM was originally an initialism for Low Level Virtual Machine. However, the LLVM project evolved into an umbrella project that has little relationship to what most current developers think of as a virtual machine.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With