Linking with GCC doesn't detect -fPIC flag

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I am trying to link some files. Here is my command:



gcc -T linker.ld -o Stack Berry.bin -ffreestanding -O2 -nostlib kernel.o boot.o -fPIC -lgcc


How ever, I get this error:



/usr/bin/ld: boot.o: relocation R_X86_64_32 against `.multiboot' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output


I have included the -fPIC argument, have I just put it in the wrong place? I haven't been able to find any thing for the syntax for this flag. Thanks!










share|improve this question







New contributor




Milo Banks is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1




    The -fPIC option must be applied during the compile phase (the command that generates the object files) I think - rather than the link phase, as you are showing
    – steeldriver
    21 hours ago










  • faceplam. Thanks. Let me try it.
    – Milo Banks
    21 hours ago










  • It doesn't seem to work. I tried it on compiling the GAS code (not a arg), and the command that generates the object file. It does not seem to work. gcc -fPIC -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
    – Milo Banks
    21 hours ago










  • (1) My first guess (and it is only a guess) was that it’s a command-line order problem. Have you tried changing the order of the command line? (2) Actually reading the “recompile with -fPIC” error make me doubt my first guess and believe that @steeldriver has the right idea. … (Cont’d)
    – Scott
    20 hours ago











  • (Cont’d) …  (3) People will say that this question is off-topic here, and belongs on Stack Overflow. I believe that it’s on-topic here, but I agree that it is likely to get answered more quickly and accurately on Stack Overflow. If you don’t get an answer here, and the question doesn’t get migrated, I suggest that you flag it and ask to have it moved. Please don’t just repost the question.
    – Scott
    20 hours ago














up vote
0
down vote

favorite












I am trying to link some files. Here is my command:



gcc -T linker.ld -o Stack Berry.bin -ffreestanding -O2 -nostlib kernel.o boot.o -fPIC -lgcc


How ever, I get this error:



/usr/bin/ld: boot.o: relocation R_X86_64_32 against `.multiboot' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output


I have included the -fPIC argument, have I just put it in the wrong place? I haven't been able to find any thing for the syntax for this flag. Thanks!










share|improve this question







New contributor




Milo Banks is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1




    The -fPIC option must be applied during the compile phase (the command that generates the object files) I think - rather than the link phase, as you are showing
    – steeldriver
    21 hours ago










  • faceplam. Thanks. Let me try it.
    – Milo Banks
    21 hours ago










  • It doesn't seem to work. I tried it on compiling the GAS code (not a arg), and the command that generates the object file. It does not seem to work. gcc -fPIC -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
    – Milo Banks
    21 hours ago










  • (1) My first guess (and it is only a guess) was that it’s a command-line order problem. Have you tried changing the order of the command line? (2) Actually reading the “recompile with -fPIC” error make me doubt my first guess and believe that @steeldriver has the right idea. … (Cont’d)
    – Scott
    20 hours ago











  • (Cont’d) …  (3) People will say that this question is off-topic here, and belongs on Stack Overflow. I believe that it’s on-topic here, but I agree that it is likely to get answered more quickly and accurately on Stack Overflow. If you don’t get an answer here, and the question doesn’t get migrated, I suggest that you flag it and ask to have it moved. Please don’t just repost the question.
    – Scott
    20 hours ago












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to link some files. Here is my command:



gcc -T linker.ld -o Stack Berry.bin -ffreestanding -O2 -nostlib kernel.o boot.o -fPIC -lgcc


How ever, I get this error:



/usr/bin/ld: boot.o: relocation R_X86_64_32 against `.multiboot' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output


I have included the -fPIC argument, have I just put it in the wrong place? I haven't been able to find any thing for the syntax for this flag. Thanks!










share|improve this question







New contributor




Milo Banks is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am trying to link some files. Here is my command:



gcc -T linker.ld -o Stack Berry.bin -ffreestanding -O2 -nostlib kernel.o boot.o -fPIC -lgcc


How ever, I get this error:



/usr/bin/ld: boot.o: relocation R_X86_64_32 against `.multiboot' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output


I have included the -fPIC argument, have I just put it in the wrong place? I haven't been able to find any thing for the syntax for this flag. Thanks!







ld multiboot






share|improve this question







New contributor




Milo Banks is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Milo Banks is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Milo Banks is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 22 hours ago









Milo Banks

1




1




New contributor




Milo Banks is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Milo Banks is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Milo Banks is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 1




    The -fPIC option must be applied during the compile phase (the command that generates the object files) I think - rather than the link phase, as you are showing
    – steeldriver
    21 hours ago










  • faceplam. Thanks. Let me try it.
    – Milo Banks
    21 hours ago










  • It doesn't seem to work. I tried it on compiling the GAS code (not a arg), and the command that generates the object file. It does not seem to work. gcc -fPIC -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
    – Milo Banks
    21 hours ago










  • (1) My first guess (and it is only a guess) was that it’s a command-line order problem. Have you tried changing the order of the command line? (2) Actually reading the “recompile with -fPIC” error make me doubt my first guess and believe that @steeldriver has the right idea. … (Cont’d)
    – Scott
    20 hours ago











  • (Cont’d) …  (3) People will say that this question is off-topic here, and belongs on Stack Overflow. I believe that it’s on-topic here, but I agree that it is likely to get answered more quickly and accurately on Stack Overflow. If you don’t get an answer here, and the question doesn’t get migrated, I suggest that you flag it and ask to have it moved. Please don’t just repost the question.
    – Scott
    20 hours ago












  • 1




    The -fPIC option must be applied during the compile phase (the command that generates the object files) I think - rather than the link phase, as you are showing
    – steeldriver
    21 hours ago










  • faceplam. Thanks. Let me try it.
    – Milo Banks
    21 hours ago










  • It doesn't seem to work. I tried it on compiling the GAS code (not a arg), and the command that generates the object file. It does not seem to work. gcc -fPIC -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
    – Milo Banks
    21 hours ago










  • (1) My first guess (and it is only a guess) was that it’s a command-line order problem. Have you tried changing the order of the command line? (2) Actually reading the “recompile with -fPIC” error make me doubt my first guess and believe that @steeldriver has the right idea. … (Cont’d)
    – Scott
    20 hours ago











  • (Cont’d) …  (3) People will say that this question is off-topic here, and belongs on Stack Overflow. I believe that it’s on-topic here, but I agree that it is likely to get answered more quickly and accurately on Stack Overflow. If you don’t get an answer here, and the question doesn’t get migrated, I suggest that you flag it and ask to have it moved. Please don’t just repost the question.
    – Scott
    20 hours ago







1




1




The -fPIC option must be applied during the compile phase (the command that generates the object files) I think - rather than the link phase, as you are showing
– steeldriver
21 hours ago




The -fPIC option must be applied during the compile phase (the command that generates the object files) I think - rather than the link phase, as you are showing
– steeldriver
21 hours ago












faceplam. Thanks. Let me try it.
– Milo Banks
21 hours ago




faceplam. Thanks. Let me try it.
– Milo Banks
21 hours ago












It doesn't seem to work. I tried it on compiling the GAS code (not a arg), and the command that generates the object file. It does not seem to work. gcc -fPIC -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
– Milo Banks
21 hours ago




It doesn't seem to work. I tried it on compiling the GAS code (not a arg), and the command that generates the object file. It does not seem to work. gcc -fPIC -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
– Milo Banks
21 hours ago












(1) My first guess (and it is only a guess) was that it’s a command-line order problem. Have you tried changing the order of the command line? (2) Actually reading the “recompile with -fPIC” error make me doubt my first guess and believe that @steeldriver has the right idea. … (Cont’d)
– Scott
20 hours ago





(1) My first guess (and it is only a guess) was that it’s a command-line order problem. Have you tried changing the order of the command line? (2) Actually reading the “recompile with -fPIC” error make me doubt my first guess and believe that @steeldriver has the right idea. … (Cont’d)
– Scott
20 hours ago













(Cont’d) …  (3) People will say that this question is off-topic here, and belongs on Stack Overflow. I believe that it’s on-topic here, but I agree that it is likely to get answered more quickly and accurately on Stack Overflow. If you don’t get an answer here, and the question doesn’t get migrated, I suggest that you flag it and ask to have it moved. Please don’t just repost the question.
– Scott
20 hours ago




(Cont’d) …  (3) People will say that this question is off-topic here, and belongs on Stack Overflow. I believe that it’s on-topic here, but I agree that it is likely to get answered more quickly and accurately on Stack Overflow. If you don’t get an answer here, and the question doesn’t get migrated, I suggest that you flag it and ask to have it moved. Please don’t just repost the question.
– Scott
20 hours ago










1 Answer
1






active

oldest

votes

















up vote
0
down vote













Your boot.o has a .multiboot elf section, which is incompatible with -fPIC. You can try to compile boot.o with -fPIC but that should fail.



See https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#OS-image-format for the header.



On the other hand, there's little sense in creating a bootable object with -fPIC. Even if there was a "dynamic loader", there can't be anything to dynamically link against during the boot process.






share|improve this answer




















  • I could only find info on the header and the flag value, and it matched up with my boot.s. BTW the boot.o is an object file, non-compilable, as it should be boot.s.
    – Milo Banks
    21 hours ago











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Milo Banks is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481358%2flinking-with-gcc-doesnt-detect-fpic-flag%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Your boot.o has a .multiboot elf section, which is incompatible with -fPIC. You can try to compile boot.o with -fPIC but that should fail.



See https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#OS-image-format for the header.



On the other hand, there's little sense in creating a bootable object with -fPIC. Even if there was a "dynamic loader", there can't be anything to dynamically link against during the boot process.






share|improve this answer




















  • I could only find info on the header and the flag value, and it matched up with my boot.s. BTW the boot.o is an object file, non-compilable, as it should be boot.s.
    – Milo Banks
    21 hours ago















up vote
0
down vote













Your boot.o has a .multiboot elf section, which is incompatible with -fPIC. You can try to compile boot.o with -fPIC but that should fail.



See https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#OS-image-format for the header.



On the other hand, there's little sense in creating a bootable object with -fPIC. Even if there was a "dynamic loader", there can't be anything to dynamically link against during the boot process.






share|improve this answer




















  • I could only find info on the header and the flag value, and it matched up with my boot.s. BTW the boot.o is an object file, non-compilable, as it should be boot.s.
    – Milo Banks
    21 hours ago













up vote
0
down vote










up vote
0
down vote









Your boot.o has a .multiboot elf section, which is incompatible with -fPIC. You can try to compile boot.o with -fPIC but that should fail.



See https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#OS-image-format for the header.



On the other hand, there's little sense in creating a bootable object with -fPIC. Even if there was a "dynamic loader", there can't be anything to dynamically link against during the boot process.






share|improve this answer












Your boot.o has a .multiboot elf section, which is incompatible with -fPIC. You can try to compile boot.o with -fPIC but that should fail.



See https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#OS-image-format for the header.



On the other hand, there's little sense in creating a bootable object with -fPIC. Even if there was a "dynamic loader", there can't be anything to dynamically link against during the boot process.







share|improve this answer












share|improve this answer



share|improve this answer










answered 21 hours ago









V13

2,646613




2,646613











  • I could only find info on the header and the flag value, and it matched up with my boot.s. BTW the boot.o is an object file, non-compilable, as it should be boot.s.
    – Milo Banks
    21 hours ago

















  • I could only find info on the header and the flag value, and it matched up with my boot.s. BTW the boot.o is an object file, non-compilable, as it should be boot.s.
    – Milo Banks
    21 hours ago
















I could only find info on the header and the flag value, and it matched up with my boot.s. BTW the boot.o is an object file, non-compilable, as it should be boot.s.
– Milo Banks
21 hours ago





I could only find info on the header and the flag value, and it matched up with my boot.s. BTW the boot.o is an object file, non-compilable, as it should be boot.s.
– Milo Banks
21 hours ago











Milo Banks is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















Milo Banks is a new contributor. Be nice, and check out our Code of Conduct.












Milo Banks is a new contributor. Be nice, and check out our Code of Conduct.











Milo Banks is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481358%2flinking-with-gcc-doesnt-detect-fpic-flag%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay