Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 319
OMGtechy Avatar asked Oct 15 '15 09:10

OMGtechy


People also ask

What is an LLVM 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.

Is LLVM a virtual machine?

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.

What is LLVM in Rust?

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.

What is LLVM in Clang?

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.


1 Answers

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.

like image 163
Abyx Avatar answered Oct 19 '22 20:10

Abyx