Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3235590
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:31:27+00:00 2026-05-17T17:31:27+00:00

I am creating an i386 ELF executable that needs to import a function from

  • 0

I am creating an i386 ELF executable that needs to import a function from libc6. (It’s printf, by the way.)

I have created a very small ELF executable that prints “Hello, world!” to the console by using the Linux kernel interrupt 0x80. This is not optimal and I would like to have the application make use of libc instead.

Here is what I have so far: (credit to this page for most of the structure alignment code.)

BITS 32

            org     0x08048000

ehdr:                                                 ; Elf32_Ehdr
            db      0x7F, "ELF", 1, 1, 1, 0         ;   e_ident
    times 8 db      0
            dw      2                               ;   e_type
            dw      3                               ;   e_machine
            dd      1                               ;   e_version
            dd      _start                          ;   e_entry
            dd      52
            dd      0                               ;   e_shoff
            dd      0                               ;   e_flags
            dw      52
            dw      32
            dw      1                               ;   e_phnum
            dw      0                               ;   e_shentsize
            dw      0                               ;   e_shnum
            dw      0                               ;   e_shstrndx

;   this is the header for the code section

            dd      1                               ;   p_type
            dd      0                               ;   p_offset
            dd      $$                              ;   p_vaddr
            dd      $$                              ;   p_paddr
            dd      filesize                        ;   p_filesz
            dd      filesize                        ;   p_memsz
            dd      5                               ;   p_flags
            dd      0x1000                          ;   p_align

_start:

            ; We want to print the string

    mov eax,4            ; 'write' system call
    mov ebx,1            ; file descriptor 1 = screen
    mov ecx,teststr      ; string to write
    mov edx,14           ; length of string to write
    int 80h              ; call the kernel

    ; Terminate program
    mov eax,1            ; 'exit' system call
    mov ebx,0            ; exit with error code 0
    int 80h              ; call the kernel

_stringtable:

            teststr db "Hello, world!",10,0

filesize      equ     $ - $$

I think I need to add another program header for imports, but I really don’t know – nor am I familiar with the format of the contents of that section.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:31:27+00:00Added an answer on May 17, 2026 at 5:31 pm

    If you’re willing to let the linker do its job, this is enough (GAS syntax; compile with gcc hello.s):

            .text
            .globl main
            .type main, @function
    main:
            leal    .LC0, %eax
            pushl   %eax
            call    puts
            xorl    %eax, %eax
            ret
            .size main, .-main
    .LC0:
            .asciz  "Hello, world!"
    

    (Technically .LC0 should be put into .rodata but I can’t remember exactly how you do that and I’m not on my Linux box right now. Also, this doesn’t maintain any stack pointer alignment, which shouldn’t be a problem for a toy program like this, but I make no promises.)

    If you really want to construct the entire executable by hand, first read this book: http://www.iecc.com/linker/ Then you’ll need to read the ELF specification, the System V generic ABI, and the x86-32 psABI supplement; these can all be found here: http://refspecs.freestandards.org/ . Then, use readelf, objdump, and/or hexdump to dismantle the executable image you get from compiling the above and work out how it’s constructed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Creating a patch is very easy in SubVersion, With Tortoise, you right-click and select
When creating a web application, and lets say you have a User object denoting
While creating classes in Java I often find myself creating instance-level collections that I
Creating hashes of hashes in Ruby allows for convenient two (or more) dimensional lookups.
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
Creating an XPathDocument with referenced DTD sometimes throws a web exception. Why?
While creating a file synchronization program in C# I tried to make a method
When creating a criteria in NHibernate I can use Restriction.In() or Restriction.InG() What is
When creating a UserControl in WPF, I find it convenient to give it some
When creating a setup/MSI with Visual Studio is it possible to make a setup

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.