How to compile against an interpreter for mips gcc?

Clash Royale CLAN TAG#URR8PPP
I tossed out the old question that used to be here as it is no longer relevant for the reasons listed below in bold. The question itself still stands, it's just the system I was trying to cross-compile for no longer exists. The old question has been copied to Pastebin.
I figured out that I could flash firmware for F@ST 2704N from OpenWRT.org. I used the link with the luci web interface and I now have OpenWRT on my router. This question is still valid because I would like to learn how to cross compile programs for my router, but now it should be easier since I am not trying to work against the builtin firmware.
How can I compile my programs to run on Mips32 version 1 processor that is running OpenWRT?
Use Interpreter Directly:
root@OpenWrt:~# /lib/ld-musl-mips-sf.so.1 hello
/lib/ld-musl-mips-sf.so.1: hello: Not a valid dynamic program
root@OpenWrt:~# ./hello
Segmentation fault
CPU INFO:
root@OpenWrt:~# cat /proc/cpuinfo
system type : bcm63xx/F@ST2704N (0x6318/0xB0)
machine : Sagem F@ST2704N
processor : 0
cpu model : Broadcom BMIPS3300 V3.3
BogoMIPS : 332.54
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : no
isa : mips1 mips2 mips32r1
ASEs implemented :
shadow register sets : 1
kscratch registers : 0
package : 0
core : 0
VCED exceptions : not available
VCEI exceptions : not available
Linux Version:
root@OpenWrt:~# cat /proc/version
Linux version 4.1.4 (thepeople@viasatpilot) (gcc version 4.8.3 (OpenWrt/Linaro GCC 4.8-2014.04 r46566) ) #1 Fri Aug 7 05:54:20 CEST 2015
Onboard Binary:
Alexs-MacBook-Air:hello-world senor$ file ls
ls: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-mips-sf.so.1, stripped
Alexs-MacBook-Air:hello-world senor$ /opt/cross/gcc-mips/bin/mips-netbsd-elf-readelf -h ls
ELF Header:
Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, big endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0x403990
Start of program headers: 52 (bytes into file)
Start of section headers: 427656 (bytes into file)
Flags: 0x50001005, noreorder, cpic, o32, mips32
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 7
Size of section headers: 40 (bytes)
Number of section headers: 29
Section header string table index: 28
My Binary:
Alexs-MacBook-Air:hello-world senor$ file hello
hello: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), statically linked, with debug_info, not stripped
Alexs-MacBook-Air:hello-world senor$ /opt/cross/gcc-mips/bin/mips-netbsd-elf-readelf -h hello
ELF Header:
Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, big endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0xa0020004
Start of program headers: 52 (bytes into file)
Start of section headers: 200884 (bytes into file)
Flags: 0x50001001, noreorder, o32, mips32
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 2
Size of section headers: 40 (bytes)
Number of section headers: 29
Section header string table index: 28
Hello Binary Source Code:
#include <stdio.h>
int main()
printf("Hello MIPS! n");
return 0;
The command I used to compile the hello binary is /opt/cross/gcc-mips/bin/mips-netbsd-elf-gcc -mips32 -Tidt.ld -static hello.c -o hello.
I tried compiling the program using the command /opt/cross/gcc-mips/bin/mips-netbsd-elf-gcc -mips32 -Tidt.ld -dynamic-linker=/lib/ld-musl-mips-sf.so.1 -static hello.c -o hello-inter, but it generates a lot of files and produces the same binary as if I didn't add that new linker option. I think I need to link the binary from source, but I could be wrong.
linux mips
add a comment |
I tossed out the old question that used to be here as it is no longer relevant for the reasons listed below in bold. The question itself still stands, it's just the system I was trying to cross-compile for no longer exists. The old question has been copied to Pastebin.
I figured out that I could flash firmware for F@ST 2704N from OpenWRT.org. I used the link with the luci web interface and I now have OpenWRT on my router. This question is still valid because I would like to learn how to cross compile programs for my router, but now it should be easier since I am not trying to work against the builtin firmware.
How can I compile my programs to run on Mips32 version 1 processor that is running OpenWRT?
Use Interpreter Directly:
root@OpenWrt:~# /lib/ld-musl-mips-sf.so.1 hello
/lib/ld-musl-mips-sf.so.1: hello: Not a valid dynamic program
root@OpenWrt:~# ./hello
Segmentation fault
CPU INFO:
root@OpenWrt:~# cat /proc/cpuinfo
system type : bcm63xx/F@ST2704N (0x6318/0xB0)
machine : Sagem F@ST2704N
processor : 0
cpu model : Broadcom BMIPS3300 V3.3
BogoMIPS : 332.54
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : no
isa : mips1 mips2 mips32r1
ASEs implemented :
shadow register sets : 1
kscratch registers : 0
package : 0
core : 0
VCED exceptions : not available
VCEI exceptions : not available
Linux Version:
root@OpenWrt:~# cat /proc/version
Linux version 4.1.4 (thepeople@viasatpilot) (gcc version 4.8.3 (OpenWrt/Linaro GCC 4.8-2014.04 r46566) ) #1 Fri Aug 7 05:54:20 CEST 2015
Onboard Binary:
Alexs-MacBook-Air:hello-world senor$ file ls
ls: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-mips-sf.so.1, stripped
Alexs-MacBook-Air:hello-world senor$ /opt/cross/gcc-mips/bin/mips-netbsd-elf-readelf -h ls
ELF Header:
Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, big endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0x403990
Start of program headers: 52 (bytes into file)
Start of section headers: 427656 (bytes into file)
Flags: 0x50001005, noreorder, cpic, o32, mips32
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 7
Size of section headers: 40 (bytes)
Number of section headers: 29
Section header string table index: 28
My Binary:
Alexs-MacBook-Air:hello-world senor$ file hello
hello: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), statically linked, with debug_info, not stripped
Alexs-MacBook-Air:hello-world senor$ /opt/cross/gcc-mips/bin/mips-netbsd-elf-readelf -h hello
ELF Header:
Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, big endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0xa0020004
Start of program headers: 52 (bytes into file)
Start of section headers: 200884 (bytes into file)
Flags: 0x50001001, noreorder, o32, mips32
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 2
Size of section headers: 40 (bytes)
Number of section headers: 29
Section header string table index: 28
Hello Binary Source Code:
#include <stdio.h>
int main()
printf("Hello MIPS! n");
return 0;
The command I used to compile the hello binary is /opt/cross/gcc-mips/bin/mips-netbsd-elf-gcc -mips32 -Tidt.ld -static hello.c -o hello.
I tried compiling the program using the command /opt/cross/gcc-mips/bin/mips-netbsd-elf-gcc -mips32 -Tidt.ld -dynamic-linker=/lib/ld-musl-mips-sf.so.1 -static hello.c -o hello-inter, but it generates a lot of files and produces the same binary as if I didn't add that new linker option. I think I need to link the binary from source, but I could be wrong.
linux mips
I've got to the bottom of your question and I'm still not sure what it is you're actually asking.
– roaima
Jan 22 at 21:52
I am trying to compile a program for the F@ST1704N router. I am currently working on a hello world program to just get things started, but I am having trouble getting the hello world program to run.
– SenorContento
Jan 22 at 22:17
1
Could you compile it statically? Maybe so it won't die on the spot. Reopen vote given.
– peterh
Jan 25 at 1:24
I archived some of my comments in the same Pastebin link that I archived the old question. For those that don't know, the old question was for the stock firmware on my router. I replaced the firmware, so I updated the question accordingly.
– SenorContento
Jan 27 at 16:10
1
I have reopened your question. Please go ahead and post your answer.
– terdon♦
Jan 28 at 9:51
add a comment |
I tossed out the old question that used to be here as it is no longer relevant for the reasons listed below in bold. The question itself still stands, it's just the system I was trying to cross-compile for no longer exists. The old question has been copied to Pastebin.
I figured out that I could flash firmware for F@ST 2704N from OpenWRT.org. I used the link with the luci web interface and I now have OpenWRT on my router. This question is still valid because I would like to learn how to cross compile programs for my router, but now it should be easier since I am not trying to work against the builtin firmware.
How can I compile my programs to run on Mips32 version 1 processor that is running OpenWRT?
Use Interpreter Directly:
root@OpenWrt:~# /lib/ld-musl-mips-sf.so.1 hello
/lib/ld-musl-mips-sf.so.1: hello: Not a valid dynamic program
root@OpenWrt:~# ./hello
Segmentation fault
CPU INFO:
root@OpenWrt:~# cat /proc/cpuinfo
system type : bcm63xx/F@ST2704N (0x6318/0xB0)
machine : Sagem F@ST2704N
processor : 0
cpu model : Broadcom BMIPS3300 V3.3
BogoMIPS : 332.54
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : no
isa : mips1 mips2 mips32r1
ASEs implemented :
shadow register sets : 1
kscratch registers : 0
package : 0
core : 0
VCED exceptions : not available
VCEI exceptions : not available
Linux Version:
root@OpenWrt:~# cat /proc/version
Linux version 4.1.4 (thepeople@viasatpilot) (gcc version 4.8.3 (OpenWrt/Linaro GCC 4.8-2014.04 r46566) ) #1 Fri Aug 7 05:54:20 CEST 2015
Onboard Binary:
Alexs-MacBook-Air:hello-world senor$ file ls
ls: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-mips-sf.so.1, stripped
Alexs-MacBook-Air:hello-world senor$ /opt/cross/gcc-mips/bin/mips-netbsd-elf-readelf -h ls
ELF Header:
Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, big endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0x403990
Start of program headers: 52 (bytes into file)
Start of section headers: 427656 (bytes into file)
Flags: 0x50001005, noreorder, cpic, o32, mips32
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 7
Size of section headers: 40 (bytes)
Number of section headers: 29
Section header string table index: 28
My Binary:
Alexs-MacBook-Air:hello-world senor$ file hello
hello: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), statically linked, with debug_info, not stripped
Alexs-MacBook-Air:hello-world senor$ /opt/cross/gcc-mips/bin/mips-netbsd-elf-readelf -h hello
ELF Header:
Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, big endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0xa0020004
Start of program headers: 52 (bytes into file)
Start of section headers: 200884 (bytes into file)
Flags: 0x50001001, noreorder, o32, mips32
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 2
Size of section headers: 40 (bytes)
Number of section headers: 29
Section header string table index: 28
Hello Binary Source Code:
#include <stdio.h>
int main()
printf("Hello MIPS! n");
return 0;
The command I used to compile the hello binary is /opt/cross/gcc-mips/bin/mips-netbsd-elf-gcc -mips32 -Tidt.ld -static hello.c -o hello.
I tried compiling the program using the command /opt/cross/gcc-mips/bin/mips-netbsd-elf-gcc -mips32 -Tidt.ld -dynamic-linker=/lib/ld-musl-mips-sf.so.1 -static hello.c -o hello-inter, but it generates a lot of files and produces the same binary as if I didn't add that new linker option. I think I need to link the binary from source, but I could be wrong.
linux mips
I tossed out the old question that used to be here as it is no longer relevant for the reasons listed below in bold. The question itself still stands, it's just the system I was trying to cross-compile for no longer exists. The old question has been copied to Pastebin.
I figured out that I could flash firmware for F@ST 2704N from OpenWRT.org. I used the link with the luci web interface and I now have OpenWRT on my router. This question is still valid because I would like to learn how to cross compile programs for my router, but now it should be easier since I am not trying to work against the builtin firmware.
How can I compile my programs to run on Mips32 version 1 processor that is running OpenWRT?
Use Interpreter Directly:
root@OpenWrt:~# /lib/ld-musl-mips-sf.so.1 hello
/lib/ld-musl-mips-sf.so.1: hello: Not a valid dynamic program
root@OpenWrt:~# ./hello
Segmentation fault
CPU INFO:
root@OpenWrt:~# cat /proc/cpuinfo
system type : bcm63xx/F@ST2704N (0x6318/0xB0)
machine : Sagem F@ST2704N
processor : 0
cpu model : Broadcom BMIPS3300 V3.3
BogoMIPS : 332.54
wait instruction : yes
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : yes
hardware watchpoint : no
isa : mips1 mips2 mips32r1
ASEs implemented :
shadow register sets : 1
kscratch registers : 0
package : 0
core : 0
VCED exceptions : not available
VCEI exceptions : not available
Linux Version:
root@OpenWrt:~# cat /proc/version
Linux version 4.1.4 (thepeople@viasatpilot) (gcc version 4.8.3 (OpenWrt/Linaro GCC 4.8-2014.04 r46566) ) #1 Fri Aug 7 05:54:20 CEST 2015
Onboard Binary:
Alexs-MacBook-Air:hello-world senor$ file ls
ls: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-mips-sf.so.1, stripped
Alexs-MacBook-Air:hello-world senor$ /opt/cross/gcc-mips/bin/mips-netbsd-elf-readelf -h ls
ELF Header:
Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, big endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0x403990
Start of program headers: 52 (bytes into file)
Start of section headers: 427656 (bytes into file)
Flags: 0x50001005, noreorder, cpic, o32, mips32
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 7
Size of section headers: 40 (bytes)
Number of section headers: 29
Section header string table index: 28
My Binary:
Alexs-MacBook-Air:hello-world senor$ file hello
hello: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), statically linked, with debug_info, not stripped
Alexs-MacBook-Air:hello-world senor$ /opt/cross/gcc-mips/bin/mips-netbsd-elf-readelf -h hello
ELF Header:
Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, big endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0xa0020004
Start of program headers: 52 (bytes into file)
Start of section headers: 200884 (bytes into file)
Flags: 0x50001001, noreorder, o32, mips32
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 2
Size of section headers: 40 (bytes)
Number of section headers: 29
Section header string table index: 28
Hello Binary Source Code:
#include <stdio.h>
int main()
printf("Hello MIPS! n");
return 0;
The command I used to compile the hello binary is /opt/cross/gcc-mips/bin/mips-netbsd-elf-gcc -mips32 -Tidt.ld -static hello.c -o hello.
I tried compiling the program using the command /opt/cross/gcc-mips/bin/mips-netbsd-elf-gcc -mips32 -Tidt.ld -dynamic-linker=/lib/ld-musl-mips-sf.so.1 -static hello.c -o hello-inter, but it generates a lot of files and produces the same binary as if I didn't add that new linker option. I think I need to link the binary from source, but I could be wrong.
linux mips
linux mips
edited Jan 28 at 21:10
SenorContento
asked Jan 22 at 16:09
SenorContentoSenorContento
84114
84114
I've got to the bottom of your question and I'm still not sure what it is you're actually asking.
– roaima
Jan 22 at 21:52
I am trying to compile a program for the F@ST1704N router. I am currently working on a hello world program to just get things started, but I am having trouble getting the hello world program to run.
– SenorContento
Jan 22 at 22:17
1
Could you compile it statically? Maybe so it won't die on the spot. Reopen vote given.
– peterh
Jan 25 at 1:24
I archived some of my comments in the same Pastebin link that I archived the old question. For those that don't know, the old question was for the stock firmware on my router. I replaced the firmware, so I updated the question accordingly.
– SenorContento
Jan 27 at 16:10
1
I have reopened your question. Please go ahead and post your answer.
– terdon♦
Jan 28 at 9:51
add a comment |
I've got to the bottom of your question and I'm still not sure what it is you're actually asking.
– roaima
Jan 22 at 21:52
I am trying to compile a program for the F@ST1704N router. I am currently working on a hello world program to just get things started, but I am having trouble getting the hello world program to run.
– SenorContento
Jan 22 at 22:17
1
Could you compile it statically? Maybe so it won't die on the spot. Reopen vote given.
– peterh
Jan 25 at 1:24
I archived some of my comments in the same Pastebin link that I archived the old question. For those that don't know, the old question was for the stock firmware on my router. I replaced the firmware, so I updated the question accordingly.
– SenorContento
Jan 27 at 16:10
1
I have reopened your question. Please go ahead and post your answer.
– terdon♦
Jan 28 at 9:51
I've got to the bottom of your question and I'm still not sure what it is you're actually asking.
– roaima
Jan 22 at 21:52
I've got to the bottom of your question and I'm still not sure what it is you're actually asking.
– roaima
Jan 22 at 21:52
I am trying to compile a program for the F@ST1704N router. I am currently working on a hello world program to just get things started, but I am having trouble getting the hello world program to run.
– SenorContento
Jan 22 at 22:17
I am trying to compile a program for the F@ST1704N router. I am currently working on a hello world program to just get things started, but I am having trouble getting the hello world program to run.
– SenorContento
Jan 22 at 22:17
1
1
Could you compile it statically? Maybe so it won't die on the spot. Reopen vote given.
– peterh
Jan 25 at 1:24
Could you compile it statically? Maybe so it won't die on the spot. Reopen vote given.
– peterh
Jan 25 at 1:24
I archived some of my comments in the same Pastebin link that I archived the old question. For those that don't know, the old question was for the stock firmware on my router. I replaced the firmware, so I updated the question accordingly.
– SenorContento
Jan 27 at 16:10
I archived some of my comments in the same Pastebin link that I archived the old question. For those that don't know, the old question was for the stock firmware on my router. I replaced the firmware, so I updated the question accordingly.
– SenorContento
Jan 27 at 16:10
1
1
I have reopened your question. Please go ahead and post your answer.
– terdon♦
Jan 28 at 9:51
I have reopened your question. Please go ahead and post your answer.
– terdon♦
Jan 28 at 9:51
add a comment |
1 Answer
1
active
oldest
votes
I found this guide on OpenWRT.org which helped me learn how to install buildtools and I just modified the instructions to fit my version of OpenWRT.
I checked out git commit 70255e3d624cd393612069aae0a859d1acbbeeae (tag: v18.06.1) and I set the settings:
system "Broadcom BCM63xx"
subtarget "generic"
profile "Sagem F@ST2704N"
I also set the PATH environment variable to have path/to/project/source/staging_dir/toolchain-mips_mips32_gcc-7.3.0_musl/bin and executed the command mips-openwrt-linux-gcc hello.c -o hello.
I should mention that I had to install gnu-getopt and gnu-time because I am compiling on OSX.
Also, as an added bonus, when I tested compiling against an existing program, such as BusyBox, I was able to compile BusyBox using the command LDFLAGS="--static" make CROSS_COMPILE="mips-openwrt-linux-".
Edit:
For those that are interested in why ELF files have interpreters, the interpreter is needed to setup the environment before the program is loaded. The quote comes from a blog post at Christian Aichinger's thoughts from the section "Program loading in the kernel".
"Statically linked binaries can do without an interpreter; dynamically linked programs always need /lib/ld-linux.so as interpreter because it includes some startup code, loads shared libraries needed by the binary, and performs relocations."
I suspect the reason why my program kept saying "Killed" (on the original Sagemcom firmware) even when I linked it statically is because the router may have been designed to confuse the user that is trying to run the program to prevent unauthorized execution. I did figure out how to compile uClibc and got it working on the original firmware and a separate Sagemcom device (unrelated to the one asked about in this question).
add a comment |
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',
autoActivateHeartbeat: false,
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
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f496003%2fhow-to-compile-against-an-interpreter-for-mips-gcc%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I found this guide on OpenWRT.org which helped me learn how to install buildtools and I just modified the instructions to fit my version of OpenWRT.
I checked out git commit 70255e3d624cd393612069aae0a859d1acbbeeae (tag: v18.06.1) and I set the settings:
system "Broadcom BCM63xx"
subtarget "generic"
profile "Sagem F@ST2704N"
I also set the PATH environment variable to have path/to/project/source/staging_dir/toolchain-mips_mips32_gcc-7.3.0_musl/bin and executed the command mips-openwrt-linux-gcc hello.c -o hello.
I should mention that I had to install gnu-getopt and gnu-time because I am compiling on OSX.
Also, as an added bonus, when I tested compiling against an existing program, such as BusyBox, I was able to compile BusyBox using the command LDFLAGS="--static" make CROSS_COMPILE="mips-openwrt-linux-".
Edit:
For those that are interested in why ELF files have interpreters, the interpreter is needed to setup the environment before the program is loaded. The quote comes from a blog post at Christian Aichinger's thoughts from the section "Program loading in the kernel".
"Statically linked binaries can do without an interpreter; dynamically linked programs always need /lib/ld-linux.so as interpreter because it includes some startup code, loads shared libraries needed by the binary, and performs relocations."
I suspect the reason why my program kept saying "Killed" (on the original Sagemcom firmware) even when I linked it statically is because the router may have been designed to confuse the user that is trying to run the program to prevent unauthorized execution. I did figure out how to compile uClibc and got it working on the original firmware and a separate Sagemcom device (unrelated to the one asked about in this question).
add a comment |
I found this guide on OpenWRT.org which helped me learn how to install buildtools and I just modified the instructions to fit my version of OpenWRT.
I checked out git commit 70255e3d624cd393612069aae0a859d1acbbeeae (tag: v18.06.1) and I set the settings:
system "Broadcom BCM63xx"
subtarget "generic"
profile "Sagem F@ST2704N"
I also set the PATH environment variable to have path/to/project/source/staging_dir/toolchain-mips_mips32_gcc-7.3.0_musl/bin and executed the command mips-openwrt-linux-gcc hello.c -o hello.
I should mention that I had to install gnu-getopt and gnu-time because I am compiling on OSX.
Also, as an added bonus, when I tested compiling against an existing program, such as BusyBox, I was able to compile BusyBox using the command LDFLAGS="--static" make CROSS_COMPILE="mips-openwrt-linux-".
Edit:
For those that are interested in why ELF files have interpreters, the interpreter is needed to setup the environment before the program is loaded. The quote comes from a blog post at Christian Aichinger's thoughts from the section "Program loading in the kernel".
"Statically linked binaries can do without an interpreter; dynamically linked programs always need /lib/ld-linux.so as interpreter because it includes some startup code, loads shared libraries needed by the binary, and performs relocations."
I suspect the reason why my program kept saying "Killed" (on the original Sagemcom firmware) even when I linked it statically is because the router may have been designed to confuse the user that is trying to run the program to prevent unauthorized execution. I did figure out how to compile uClibc and got it working on the original firmware and a separate Sagemcom device (unrelated to the one asked about in this question).
add a comment |
I found this guide on OpenWRT.org which helped me learn how to install buildtools and I just modified the instructions to fit my version of OpenWRT.
I checked out git commit 70255e3d624cd393612069aae0a859d1acbbeeae (tag: v18.06.1) and I set the settings:
system "Broadcom BCM63xx"
subtarget "generic"
profile "Sagem F@ST2704N"
I also set the PATH environment variable to have path/to/project/source/staging_dir/toolchain-mips_mips32_gcc-7.3.0_musl/bin and executed the command mips-openwrt-linux-gcc hello.c -o hello.
I should mention that I had to install gnu-getopt and gnu-time because I am compiling on OSX.
Also, as an added bonus, when I tested compiling against an existing program, such as BusyBox, I was able to compile BusyBox using the command LDFLAGS="--static" make CROSS_COMPILE="mips-openwrt-linux-".
Edit:
For those that are interested in why ELF files have interpreters, the interpreter is needed to setup the environment before the program is loaded. The quote comes from a blog post at Christian Aichinger's thoughts from the section "Program loading in the kernel".
"Statically linked binaries can do without an interpreter; dynamically linked programs always need /lib/ld-linux.so as interpreter because it includes some startup code, loads shared libraries needed by the binary, and performs relocations."
I suspect the reason why my program kept saying "Killed" (on the original Sagemcom firmware) even when I linked it statically is because the router may have been designed to confuse the user that is trying to run the program to prevent unauthorized execution. I did figure out how to compile uClibc and got it working on the original firmware and a separate Sagemcom device (unrelated to the one asked about in this question).
I found this guide on OpenWRT.org which helped me learn how to install buildtools and I just modified the instructions to fit my version of OpenWRT.
I checked out git commit 70255e3d624cd393612069aae0a859d1acbbeeae (tag: v18.06.1) and I set the settings:
system "Broadcom BCM63xx"
subtarget "generic"
profile "Sagem F@ST2704N"
I also set the PATH environment variable to have path/to/project/source/staging_dir/toolchain-mips_mips32_gcc-7.3.0_musl/bin and executed the command mips-openwrt-linux-gcc hello.c -o hello.
I should mention that I had to install gnu-getopt and gnu-time because I am compiling on OSX.
Also, as an added bonus, when I tested compiling against an existing program, such as BusyBox, I was able to compile BusyBox using the command LDFLAGS="--static" make CROSS_COMPILE="mips-openwrt-linux-".
Edit:
For those that are interested in why ELF files have interpreters, the interpreter is needed to setup the environment before the program is loaded. The quote comes from a blog post at Christian Aichinger's thoughts from the section "Program loading in the kernel".
"Statically linked binaries can do without an interpreter; dynamically linked programs always need /lib/ld-linux.so as interpreter because it includes some startup code, loads shared libraries needed by the binary, and performs relocations."
I suspect the reason why my program kept saying "Killed" (on the original Sagemcom firmware) even when I linked it statically is because the router may have been designed to confuse the user that is trying to run the program to prevent unauthorized execution. I did figure out how to compile uClibc and got it working on the original firmware and a separate Sagemcom device (unrelated to the one asked about in this question).
edited 6 hours ago
answered Jan 28 at 21:14
SenorContentoSenorContento
84114
84114
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f496003%2fhow-to-compile-against-an-interpreter-for-mips-gcc%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I've got to the bottom of your question and I'm still not sure what it is you're actually asking.
– roaima
Jan 22 at 21:52
I am trying to compile a program for the F@ST1704N router. I am currently working on a hello world program to just get things started, but I am having trouble getting the hello world program to run.
– SenorContento
Jan 22 at 22:17
1
Could you compile it statically? Maybe so it won't die on the spot. Reopen vote given.
– peterh
Jan 25 at 1:24
I archived some of my comments in the same Pastebin link that I archived the old question. For those that don't know, the old question was for the stock firmware on my router. I replaced the firmware, so I updated the question accordingly.
– SenorContento
Jan 27 at 16:10
1
I have reopened your question. Please go ahead and post your answer.
– terdon♦
Jan 28 at 9:51