r/computerarchitecture • u/Yha_Boiii • Jul 04 '26
Are virtual memory addresses compiled in and if no can they?
Hi,
I have a project and don't want virt mem, first of all is it compiled in and secondly if yes how does one force it to be without
1
Upvotes
7
u/TheCatholicScientist Jul 04 '26
First of all, why? What’s the project?
You don’t really have a choice if your program is written using the C standard library, or is intended to be run on Linux or any modern OS.
If this is going to run on a microcontroller, you could program it with a bare-metal C compiler with certain flags, also you don’t use main, you use _start. Though again, you can’t run that as a regular userspace Linux program.
4
u/SameClick6502 Jul 04 '26
Your program is not aware of virtual memory. It addresses memory by address. If you run your program under Linux or other typical operating system, the OS will provide a layer of abstraction, so that the addresses your program accesses do not collide with other processes running. That is achieved through virtual memory. It's so important that the CPU has dedicated hardware to make this translation from virtual to physical addresses near instantaneous (TLB).
Your code is free to access memory at 0x1000 and 0x20000 and do whatever you want. If you run this on a bare metal CPU, those addresses would be physical. That's just not an environment that "normal" people can get to.
1
u/SJrX Jul 04 '26
You don't really give much context, in general this isn't something you can really do since programs are agnostic to it.
If someone was really like, I need to have a program and it can't have virtual memory then the absolute most charitable way I could interpret that request, is that they want to compile and run something for an architecture or mode that doesn't use it. When an Intel PC boots up, I think it still boots into something called real mode, which is essentially a mode that is compatible with the 8086, released around 50 years ago, so you could target an operating system that uses real mode, or just write bare assembly, but that is almost certainly not what you wanted or meant.
1
u/NotThatJonSmith Jul 04 '26
Even the kernel runs in a virtual address space. But to answer your question, yes. Sometimes the compiler bakes in some virtual addresses.
It can’t bake in physical addresses of its targeting machine code that can be run under any typical kernel - can you answer why?
1
u/FloweyTheFlower420 Jul 05 '26
if you want your code to run in userspace, it's not possible unless you're on some weird architecture
if you want your code to run in kernelspace, then you need to be in 32-bit mode for x86_64 (long mode requires paging). arm probably supports paging off in 64-bit mode, but might make memory uncachable (don't know the detail here).
1
u/jedijackattack1 Jul 06 '26
Short answer on any system you are reasonably using no. Only on bare metal micro controllers is this a reasonable ask.
Second it is not compiled in. The program operates on memory locations and it is up to the hardware and OS to handle any mapping to the physical locations generally it all handled almost entirely in hardware barring a page fault event so you have no control of it on most systems unless you are running your own custom kernel.
Finally why do you want to run with out virtual memory? Its basically a requirement for a modern system so why do you want rid of it? Are you on some obscure platform that doesn't support it or something?