Linking with GCC doesn't detect -fPIC flag
Clash 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!
ld multiboot
New contributor
|
show 1 more comment
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!
ld multiboot
New contributor
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
|
show 1 more comment
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!
ld multiboot
New contributor
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
ld multiboot
New contributor
New contributor
New contributor
asked 22 hours ago
Milo Banks
1
1
New contributor
New contributor
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
|
show 1 more comment
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
|
show 1 more comment
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.
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Milo Banks is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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