LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 08-31-2005, 11:39 AM   #1
bong.mau
Member
 
Registered: Apr 2004
Posts: 290

Rep: Reputation: 30
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.
 
Old 08-31-2005, 11:48 AM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
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
 
Old 08-31-2005, 02:48 PM   #3
nodger
Member
 
Registered: Oct 2003
Location: Ireland
Distribution: Slackware 9.1, Ubuntu
Posts: 192

Rep: Reputation: 30
that program does something. returns a value.
 
Old 08-31-2005, 02:56 PM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
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.
 
Old 08-31-2005, 02:59 PM   #5
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 45
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
 
Old 08-31-2005, 03:04 PM   #6
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
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.
 
Old 08-31-2005, 03:10 PM   #7
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 45
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
 
Old 08-31-2005, 03:12 PM   #8
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
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...
:-)
 
Old 08-31-2005, 03:15 PM   #9
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
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.
 
Old 09-01-2005, 12:06 PM   #10
bong.mau
Member
 
Registered: Apr 2004
Posts: 290

Original Poster
Rep: Reputation: 30
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
 
Old 09-01-2005, 12:29 PM   #11
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 42
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dummy Network Mistake d0127810 Debian 11 05-24-2005 09:21 PM
Dummy question about Nautilius ??? burki Linux - General 12 03-12-2005 06:38 PM
Dummy interface?? wtf?? DertyolBA$HTARD Linux - Networking 1 11-14-2004 10:01 AM
mail server for a dummy? Big Al Linux - Networking 1 06-22-2002 02:51 AM
dummy terminal frieza Linux - Networking 3 02-27-2002 05:31 PM


All times are GMT -5. The time now is 08:48 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration