position independent code

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
shahadat
Posts: 19
Joined: Thu May 13, 2010 2:53 am

position independent code

Post by shahadat »

djgpp is not sopporting -pie or position independent code.
is there any way to make it support.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: position independent code

Post by Brynet-Inc »

DJGPP == DOS compiler suite.

I'm going to out on a limb and say that DOS does not support position independent code or executables.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
TylerH
Member
Member
Posts: 285
Joined: Tue Apr 13, 2010 8:00 pm
Contact:

Re: position independent code

Post by TylerH »

Probably not. Compile a cross compiler. See the wiki for instructions.

Is DJGPP a version of GCC? If not, you'll need to get one before you can make your cross compiler.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: position independent code

Post by Combuster »

DJGPP is GCC for DOS.

But really, you do not want to make a cross-compiler using DJGPP. You'd end up coming across about each and every bad aspect of DOS you can imagine. And besides, DJGPP itself is dated and slightly buggy.

So I repeat:
You do not want to use DJGPP </jedi mind trick>
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: position independent code

Post by qw »

Combuster wrote:So I repeat:
You do not want to use DJGPP </jedi mind trick>
I do.</Jabba the Hutt>
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: position independent code

Post by jal »

Brynet-Inc wrote:I'm going to out on a limb and say that DOS does not support position independent code or executables.
Well, COM-files were entirely position independent, as everything resided within a single segment. EXE-files, being multi-segmented, needed fixing at load time, but the file format itself could be called position independent. So unless that's not what you meant, I have to disagree.


JAL
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: position independent code

Post by Combuster »

berkus wrote:Addresses within a segment are always 0-based. How is that position independent?
How is using CS/DS instead of EBX less position independent than 32-bits PIC?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: position independent code

Post by qw »

Indeed. Segmentation can be considered position independence, albeit with a 16 byte granularity in real mode. Additionally, using segment registers saves a general purpose register of which the x86 doesn't have that many. No global offset table needed either.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: position independent code

Post by Combuster »

So? DOS apps toss segment registers around all the time - it may be old but it's not stupid enough to limit itself to 64K code/data.

Better argument please.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: position independent code

Post by Brynet-Inc »

Some alien bastard broke the tree limb I was standing on, but anyway, it seems DJGPP generates executables that don't run natively on DOS but using a 32-bit DOS extender, which itself may not have a realization of PIC/PIE and hence is a compiler feature NOP.

None of this is overly interesting anyway, it's all about some new user (..who's probably gone) and their attempt to wrangle a DOS compiler for OSDev.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: position independent code

Post by qw »

berkus wrote:Because you need different values of CS/DS when addressing this code/data, meaning you cannot simply mix several code modules without changing CS/DS whilst calling them.
This is exactly what makes an offset table unnecessary.
rdos
Member
Member
Posts: 3310
Joined: Wed Oct 01, 2008 1:55 pm

Re: position independent code

Post by rdos »

Segmentation means position indepedent. All my device-drivers are position independent, and also require no relocations. This is because the linker takes the code and data selector as an input, replacing all references to code and data segments with one of these selectors. This means a device-driver can be loaded at any linear address. And segments can be 16-bit or 32-bit, so there is no size limits to this concept either.
rdos
Member
Member
Posts: 3310
Joined: Wed Oct 01, 2008 1:55 pm

Re: position independent code

Post by rdos »

berkus wrote:Because you need different values of CS/DS when addressing this code/data, meaning you cannot simply mix several code modules without changing CS/DS whilst calling them.
There is no need to have many different code modules in the same device in a segmented OS. It is when one device calls another that far pointers are needed, otherwise a near model works perfectly well. Just forget about the useless far memory models of old DOS. This was invented because of 16-bit limitations in DOS (and the 286), and should not be used in a segmented OS that can define segments as 32-bit if needed.
Post Reply