<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>compilation Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/compilation/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/compilation/</link>
	<description></description>
	<lastBuildDate>Mon, 02 Jun 2025 13:04:51 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>compilation Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/compilation/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained</title>
		<link>https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/</link>
					<comments>https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 02 Jun 2025 13:04:50 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[C++ programming]]></category>
		<category><![CDATA[code linking]]></category>
		<category><![CDATA[coding tutorials]]></category>
		<category><![CDATA[compilation]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[executable files]]></category>
		<category><![CDATA[jump instructions]]></category>
		<category><![CDATA[linker]]></category>
		<category><![CDATA[module linking]]></category>
		<category><![CDATA[object files]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming basics]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[virtual memory]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=139</guid>

					<description><![CDATA[<p>Learn how linkers connect code modules, manage virtual memory, and handle jumps in this beginner-friendly guide to programming! #Linker #Coding</p>
<p>The post <a href="https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/">How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained" width="1380" height="776" src="https://www.youtube.com/embed/Q6B9FWCeaFs?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p>Hey everyone, let’s talk linkers! In this video, we unpack the general idea of linking in programming—taking your source code, turning it into object files, and stitching them into an executable. We dive into virtual memory, how programs use offsets, and why jump instructions matter across modules. Using simple assembly and C++ examples, we’ll show how linkers lay out modules, handle labels, and make function calls work. Whether you’re a beginner or a coder curious about what happens under the hood, this is for you! Hit subscribe, scan the QR code for more tutorials, and drop a comment with your thoughts or video ideas. Let’s keep learning and have some fun with code! #Programming #Linker #VirtualMemory #CodingExplained</p>



<p>Introduction to Linking 00:00:00<br>Compilation and Object Files 00:00:05<br>Linker Overview 00:00:32<br>Virtual Memory Explanation 00:00:42<br>Program Memory Offsets 00:01:18<br>Jump Instructions in Modules 00:02:54<br>Module Address Space 00:03:38<br>Assembler and Label Jumps 00:04:02<br>Linker’s Role in Module Layout 00:07:15<br>Function Calls Across Modules 00:08:04<br>Marking Labels as Global 00:09:31<br>External Function Calls 00:10:23<br>Data in Executables 00:11:12<br>Conclusion and Call to Subscribe 00:12:08</p>



<p>Thanks for watching!</p>



<p>Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p>Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p>Hey there, I want to talk to you very quickly about the general idea of linking your programs.</p>



<p>In previous videos I&#8217;ve described exactly how to perform the linking stage when you&#8217;re compiling</p>



<p>a program. So you write some source code, you compile the source code into object files,</p>



<p>you know each file becomes one individual object file, and then when we&#8217;re done we take all the</p>



<p>object files and we link them up into an executable program. So I&#8217;ve talked about that</p>



<p>I just wanted to talk to you about the general idea of the linking stage in general.</p>



<p>Like what is the linker? What is its job? What is it actually doing?</p>



<p>So try to keep in mind for starters, each program uses virtual memory.</p>



<p>It uses a virtual memory space.</p>



<p>So obviously on your computer you have real memory,</p>



<p>but there&#8217;s lots of layers of abstraction between the physical hardware</p>



<p>the physical hardware and the program that&#8217;s running for starters the operating system uses</p>



<p>a paging system the memory stick the memory circuitry might be doing something else for</p>



<p>error checking or just you know transport or whatever so so try and bear in mind that each</p>



<p>program thinks that it&#8217;s it thinks that itself is kind of the beginning of memory you could imagine</p>



<p>it as each program thinks that its first memory location that it has assigned to it is memory</p>



<p>location zero but that wouldn&#8217;t necessarily be the case on the computer</p>



<p>your operating system probably would have come up with an offset let&#8217;s say</p>



<p>for example you know your computer decides to launch your program it</p>



<p>creates a process it finds a chunk of memory that&#8217;s available across you know</p>



<p>one or more pages of free memory and let&#8217;s say for the sake of argument that</p>



<p>the starting offset for the for the quote-unquote real forgetting the other</p>



<p>layers layers of abstraction the real memory location of your program is going</p>



<p>of your program is going to be let&#8217;s just say like a thousand I know that&#8217;s</p>



<p>real unrealistically too low but let&#8217;s just say a thousand and then let&#8217;s say</p>



<p>that your program then thinks that it starts at memory location zero that</p>



<p>means if your program wants to access memory location 100 then under the hood</p>



<p>at the last moment right before you actually hit the RAM stick or hit the</p>



<p>page file system a translation has to be performed so if your program is trying</p>



<p>what actually happens is you know the general offset for the entire program</p>



<p>gets added to memory location 100 and then that tells the computer or the</p>



<p>operating system that what you&#8217;re actually trying to do in your program is</p>



<p>access memory location 1100 so keep in mind all of this memory is virtual</p>



<p>and the modules themselves also need to know where to jump when I say where to</p>



<p>Well, suppose for the sake of argument, you have a program that has some jump instructions</p>



<p>or go to instructions or like some conditional branching instructions, anything where execution</p>



<p>is not just going to go to the very next statement.</p>



<p>Execution is going to go somewhere else.</p>



<p>Like maybe you have an if else block.</p>



<p>It&#8217;s got to maybe jump sometimes down to the else part instead of the top if part.</p>



<p>And then when it&#8217;s done executing, it&#8217;s going to jump until after the whole block, you know,</p>



<p>There will be lots of times in all of your programs where execution kind of has to jump</p>



<p>around somewhere if the program is even a little bit complicated.</p>



<p>So that could be a jump instruction, go to in a higher level language, not assembly necessarily,</p>



<p>jump if not equal and so forth.</p>



<p>So if you imagine writing one module, you could also imagine that the module has its</p>



<p>own virtual memory address space.</p>



<p>Just imagine it for now.</p>



<p>And maybe it starts at zero.</p>



<p>at zero that&#8217;s that&#8217;s not what we&#8217;re going to say but just like imagine the module only really knows</p>



<p>about itself and so sometimes when you&#8217;re jumping for example if we&#8217;re going to jump uh when</p>



<p>something is not equal to something else we&#8217;ll jump to some label and in order to jump to that</p>



<p>label the assembler needs to know you know where is that label inside of your source code so pretend</p>



<p>just for a moment this is not like a real assembly program but just pretend for a moment that we have</p>



<p>and maybe this is like I don&#8217;t know the main label that gets jumped into from GCC and</p>



<p>so then we have like a label down here outside and we&#8217;ll do stuff and then jump back to the</p>



<p>original point so we probably have to do a label here main finish this is this is bad form but I&#8217;m</p>



<p>So if we jump, let&#8217;s compare, I don&#8217;t know, one with two or something.</p>



<p>Let&#8217;s compare RAX to RDX and we&#8217;ll just move RAX the value one and move RDX the value two</p>



<p>so they&#8217;re not actually equal.</p>



<p>And then we compare them and then we say, all right, jump if they&#8217;re not equal to this label.</p>



<p>So definitely now we know, oh, we are going to jump down to that label.</p>



<p>So execution is going to go directly down to here.</p>



<p>we&#8217;ll do something and then eventually maybe we want to jump back so we&#8217;ll say uh</p>



<p>maybe let&#8217;s do it again let&#8217;s do let&#8217;s do like a whole set of statements again we&#8217;ll say jump</p>



<p>if it is equal and we&#8217;ll just like load those two registers so one and one and then compare</p>



<p>them and then say jump if it is equal to main finish this is not a video about conditional</p>



<p>branching or jumping i&#8217;m trying to make this as simple as i can but i hope you understand the</p>



<p>but i hope you understand the point is just basically we&#8217;re jumping around within the same</p>



<p>module right so it&#8217;s easy for the program to understand where to jump if it&#8217;s in the same</p>



<p>module or i guess the the object file when we&#8217;re assembling it it&#8217;s easy to understand where to jump</p>



<p>because if we&#8217;re at line 8 here when we start to jump and then the actual label here has its first</p>



<p>instruction at line 17 well then it you know the amount of instructions to move is just the</p>



<p>the difference you know so it&#8217;s easy to say all right if our virtual address is you know this</p>



<p>when we jump and we&#8217;re going to jump this much of a difference based on where the label is then now</p>



<p>we can just compute the new virtual address to jump or the absolute address or whatever you want</p>



<p>to whatever you want to do on that particular run but how does it know where to jump in another</p>



<p>module because when we assemble this module as an object file the assembler is only running one pass</p>



<p>one pass on just this object file it doesn&#8217;t really know the addresses in the other modules</p>



<p>it doesn&#8217;t know their offsets of its labels even if it&#8217;s a c plus plus or a c module it doesn&#8217;t</p>



<p>really know the offsets it doesn&#8217;t know where the functions start and end doesn&#8217;t know anything</p>



<p>because right now if we assemble this one source code it&#8217;s only going to know about this one source</p>



<p>code right and the same goes for the other modules if we compile a c plus plus program to an object</p>



<p>a function or you know do a go to statement or something into one of these labels from this</p>



<p>module the c plus plus program won&#8217;t really know where it is it won&#8217;t know what address it&#8217;s at it</p>



<p>won&#8217;t know the offset right so that&#8217;s the job of the linker the linker looks at all of these labels</p>



<p>and all of these uh conditional branching statements and jump statements and everything</p>



<p>and it just decides for starters it decides where each module is going to start in memory so maybe</p>



<p>I don&#8217;t know if your C++ module starts up here somewhere and then it&#8217;ll say this assembly module</p>



<p>starts right after it and then another module right after that and it&#8217;ll just kind of decide</p>



<p>where every module will start in the final executable that we&#8217;re actually linking together.</p>



<p>Once it decides the layout then it knows the offset of all the different modules and therefore</p>



<p>it can compute the additional offset that it would take to get to all the labels. So then at that</p>



<p>Your C++ module will make a function call inside of, you know, some assembly module like the one we&#8217;re looking at, assuming it was written a little bit differently.</p>



<p>Main finish return.</p>



<p>I guess the way it&#8217;s written down here, it&#8217;s returning to main if we just kind of execute it as we&#8217;re looking at it.</p>



<p>But another module could could call main finish as a function and still get a return statement.</p>



<p>That would actually work, even though it&#8217;s probably bad design.</p>



<p>that your assembly sorry your C++ program wants to call a function called</p>



<p>main finish inside of this module the linker having already laid out the</p>



<p>modules and and being aware of all their offsets it knows okay so you know this</p>



<p>assembly module it was underneath the C++ module so it&#8217;ll just take that offset</p>



<p>and add it to the offset of the label itself within the module and then also</p>



<p>add that to the the virtual address or I guess the operating system will do the</p>



<p>address. But you know, the point is the linker coordinates all the jumps and the conditional</p>



<p>branches where the functions start, lays out all the modules, gets all the offsets,</p>



<p>and then starts replacing all of the conditional branches and jumps and things with the real</p>



<p>offsets that make it actually doable. Like let&#8217;s jump to exactly this memory location</p>



<p>in code exactly in quotes, because we&#8217;re still using virtual addressing.</p>



<p>idea of the linker it knows how to jump between modules um wants to link or discuss okay that&#8217;s</p>



<p>all i really wanted to say don&#8217;t forget if you want a label to be available to jump into or to</p>



<p>call as a function from outside the module you got to mark it as global so if i actually wanted</p>



<p>somebody to be able to call main finish as a function i just have to mark it as global same</p>



<p>thing for some label if i say global some label then now at this point another module could call</p>



<p>call this as a function or jump into it probably bad form to not put a return a return statement</p>



<p>at this point which means when i&#8217;m calling it up here instead of jump not equal to i probably have</p>



<p>to add more complicated logic so i can use a function call that gets jumped around if it is</p>



<p>equal but so i&#8217;m not going to go that far right now kind of complicated just for this video</p>



<p>and then also of course if you intend to jump somewhere else remember that you have to mark</p>



<p>So let&#8217;s say there&#8217;s a function in your other module, your C++ module or your C module or your assembly module.</p>



<p>You just have to mark it as extern in the text section, in the text segment, like some other function somewhere else, something like that.</p>



<p>And then once I do that, now I could actually call it, I could say, call, you know, this.</p>



<p>Actually, that&#8217;ll never get reached because the jump equal thing is at the bottom.</p>



<p>equal thing is at the bottom but I could do this I could say call it if it was actually a function</p>



<p>or I could say jump if it was just a jump point or I could say you know jump not equal to</p>



<p>the other function instead of some label something like that so lots of stuff you can do and now you</p>



<p>kind of understand the idea of linking is taking all the modules stuffing them inside of the final</p>



<p>executable and also putting data inside of the final executable you know like if you&#8217;re creating</p>



<p>So, you know, like if you&#8217;re creating a string variable in your globals area of your assembly</p>



<p>program or hard coding, any kind of string anywhere in your C++, then it&#8217;s got to be</p>



<p>inside of the executable.</p>



<p>Otherwise, it wouldn&#8217;t be anywhere when we ran the program.</p>



<p>So, yeah, it sticks the data in there.</p>



<p>It sticks the segments in there.</p>



<p>It, you know, calculates the jumps and all that stuff.</p>



<p>I just want to point out you could put strings in a configuration file.</p>



<p>of a vanilla C++ or assembly program you probably are making strings directly in the program.</p>



<p>Anyway, so I think that&#8217;s the gist of everything that I really wanted to say about what is the</p>



<p>general idea of the linker. Thanks for watching this video I hope you learned a little bit and</p>



<p>had some fun. I will see you in the next video. Hey everybody thanks for watching this video again</p>



<p>it i do hope you did learn something and have some fun if you could do me a please a small little</p>



<p>favor could you please subscribe and follow this channel or these videos or whatever it is you do</p>



<p>on the current social media website that you&#8217;re looking at right now it would really mean the</p>



<p>world to me and it&#8217;ll help make more videos and grow this community so we&#8217;ll be able to do more</p>



<p>videos longer videos better videos or just i&#8217;ll be able to keep making videos in general so please</p>



<p>and subscribe. You know, sometimes I&#8217;m sleeping in the middle of the night and I just wake up</p>



<p>because I know somebody subscribed or followed. It just wakes me up and I get filled with joy.</p>



<p>That&#8217;s exactly what happens every single time. So you could do it as a nice favor to me or you</p>



<p>could troll me if you want to just wake me up in the middle of the night, just subscribe</p>



<p>and then I&#8217;ll just wake up. I promise that&#8217;s what will happen. Also, if you look at the middle of</p>



<p>the screen right now, you should see a QR code, which you can scan in order to go to the website,</p>



<p>is also named somewhere at the bottom of this video and it&#8217;ll take you to my main website where</p>



<p>you can just kind of like see all the videos I published and the services and tutorials and</p>



<p>things that I offer and all that good stuff and uh if you have a suggestion for uh uh clarifications</p>



<p>or errata or just future videos that you want to see please leave a comment or if you just want to</p>



<p>say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever I also wake up for</p>



<p>I wake up in a cold sweat and I&#8217;m like, it would really mean the world to me.</p>



<p>I would really appreciate it.</p>



<p>So again, thank you so much for watching this video and enjoy the cool music as I fade into</p>



<p>the darkness, which is coming for us all.</p>



<p>Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/">How Linkers Work: Linking Code, Virtual Memory, and Module Jumps Explained</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/how-linkers-work-linking-code-virtual-memory-and-module-jumps-explained/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
