Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
08-31-2005, 11:39 AM
|
#1
|
|
Member
Registered: Apr 2004
Posts: 290
Rep:
|
Dummy
Hi
I need a program that do nothing !
it must contains only a return to the caller.
like iefbr14 on ibm mainframes.....: an assembler pgm containing a branch to register 14,a return to the caller...
i 'm a linux newbie,but not a computer newbie,i immagine kde is written in
C language,so if someone know where to download an alreday compiled C
pgm that "do nothing" or have patience to instruct me to write correct statements and issue the make and/or make install command ,i will reach my target.
thanks in advance
Maurizio
Last edited by bong.mau; 08-31-2005 at 11:41 AM.
|
|
|
|
08-31-2005, 11:48 AM
|
#2
|
|
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Rep:
|
I might be confused by what your asking here....
Code:
/* dummy.c */
int main () {
return 0;
}
Build instructions:
gcc -Wall -o dummy dummy.c
Execute instructions
./dummy
|
|
|
|
08-31-2005, 02:48 PM
|
#3
|
|
Member
Registered: Oct 2003
Location: Ireland
Distribution: Slackware 9.1, Ubuntu
Posts: 192
Rep:
|
that program does something. returns a value.
|
|
|
|
08-31-2005, 02:56 PM
|
#4
|
|
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Rep:
|
Quote:
|
it must contains only a return to the caller.
|
If you want nothing returned then
void main() {return;} or simply void main() {} would do the trick... however, in Linux a program is suppose to return 0 or an error code apon completion of it's execution to truly follow all the rules.
Also... so you know... KDE is written in C++ utilizing the QT API.
Last edited by jtshaw; 08-31-2005 at 02:59 PM.
|
|
|
|
08-31-2005, 02:59 PM
|
#5
|
|
Senior Member
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037
Rep:
|
hi there,
could you have a "void main" ??
what about...
Code:
/* dummy.c */
void main () {
}
the gcc compiler gives a warning but you actually gets a program that do nothing..
regards,
slackie1000
|
|
|
|
08-31-2005, 03:04 PM
|
#6
|
|
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Rep:
|
Quote:
Originally posted by slackie1000
hi there,
could you have a "void main" ??
what about...
Code:
/* dummy.c */
void main () {
}
the gcc compiler gives a warning but you actually gets a program that do nothing..
regards,
slackie1000
|
Sure you can do that... if your interested it actually causes a one line decrease in the assembly code created:
int main:
Code:
.file "dummy.c"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
addl $15, %eax
addl $15, %eax
shrl $4, %eax
sall $4, %eax
subl %eax, %esp
movl $0, %eax <--- THIS IS THE DIFFERENCE
leave
ret
.size main, .-main
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)"
void main:
Code:
.file "dummy.c"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
addl $15, %eax
addl $15, %eax
shrl $4, %eax
sall $4, %eax
subl %eax, %esp
leave
ret
.size main, .-main
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)"
I compiled this without any optimizations.. using -O3 or -Os would produce less code.
|
|
|
|
08-31-2005, 03:10 PM
|
#7
|
|
Senior Member
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037
Rep:
|
Quote:
Originally posted by jtshaw
Sure you can do that... if your interested it actually causes a one line decrease in the assembly code created:
int main:
Code:
.file "dummy.c"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
addl $15, %eax
addl $15, %eax
shrl $4, %eax
sall $4, %eax
subl %eax, %esp
movl $0, %eax <--- THIS IS THE DIFFERENCE
leave
ret
.size main, .-main
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)"
void main:
Code:
.file "dummy.c"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
addl $15, %eax
addl $15, %eax
shrl $4, %eax
sall $4, %eax
subl %eax, %esp
leave
ret
.size main, .-main
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)"
I compiled this without any optimizations.. using -O3 or -Os would produce less code.
|
woo!! that was nice... thanks for posting that jtshaw!!!
for me what was also interesting is that both executables had the same size with the default compilation: 4355
Code:
gcc -o something dummy.c
cheers,
slackie1000
|
|
|
|
08-31-2005, 03:12 PM
|
#8
|
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530
Rep: 
|
Quote:
Code:
.file "dummy.c"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
addl $15, %eax
addl $15, %eax
shrl $4, %eax
sall $4, %eax
subl %eax, %esp
movl $0, %eax <--- THIS IS THE DIFFERENCE
leave
ret
.size main, .-main
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)"
|
Looks like quite a lot, for a program that's supposed to do nothing...
:-)
|
|
|
|
08-31-2005, 03:15 PM
|
#9
|
|
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Rep:
|
 And people say functions have no overhead....
The smallest I could get the assembly output was:
Code:
.file "dummy.c"
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)"
That was compiling a file with nothing but a comment in it
Unfortunetly you can't link that, because to link and build an exe you must have a main.
The smallest I could get it that would link was
Code:
.file "dummy.c"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
popl %ebp
ret
.size main, .-main
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)"
GCC apparently doesn't bother to make sure you use the stack pointer before it saves it.
Last edited by jtshaw; 08-31-2005 at 03:17 PM.
|
|
|
|
09-01-2005, 12:06 PM
|
#10
|
|
Member
Registered: Apr 2004
Posts: 290
Original Poster
Rep:
|
Hi
First :thanks to all people that answered to my question.
i was using the dummy pgm in the mainframe environment to
reach this target...
immagine a product that starts many other pgm that may be uneseful.
the program starting is not ruled by parameters...
so i renamed the dummy pgm with the name of the original to be substituted...
the iefbr14 contains a return to register 14,then the return code is 0
because the operation is always successfull.
so the main product think to have started a sub program but instead it starts a dummy.
if the C environment does not provide automatically a return code 0
meaning successfull operation,then the dummy pgm must contain a
return code 0 setting.
Maurizio
|
|
|
|
09-01-2005, 12:29 PM
|
#11
|
|
Member
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557
Rep:
|
Quote:
|
The smallest I could get it that would link was ...
|
If you change languages, you can do better
Code:
13:20 aluser@alf:~/test/asm$ cat small.s
.globl _start
.text
_start:
movl $1, %eax
int $0x80
13:20 aluser@alf:~/test/asm$ as -o small.o small.s
13:20 aluser@alf:~/test/asm$ ld -o small small.o
13:20 aluser@alf:~/test/asm$ ./small
13:20 aluser@alf:~/test/asm$ echo $?
0
13:20 aluser@alf:~/test/asm$ ls -l small
-rwxr-xr-x 1 aluser aluser 656 Sep 1 13:20 small
Obviously, this is specific to linux x86...
It calls the exit() syscall with whatever is in %ebx as the exit value. On my system that happens to be 0.
If you don't call exit from _start, it'll segfault; _start doesn't have a calling function. When you compile something with gcc and it links with libc, libc sets up a _start that calls your main() and exits with main's return code; I've bypassed that step.
I've read it's actually possible to get a working executabe down to the size of the ELF header by putting code in unused parts of the header. You would have to create the entire executable in a hex editor at that point.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 07:29 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|