#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2010
    Posts
    17
    Rep Power
    0

    Assembly - PowerPC - GCC : location of object files?


    NOTE: After getting the feeling there are not too many assembly programmers frequenting this page, I have cross-posted to:

    http://www.daniweb.com/forums/post14...ml#post1414805
    thanks.

    Hello,

    I have been trying to learn assembly code for PPC on a Mac OS 10.5. My question pertains to determining how GCC uses libraries on the Mac to insert instructions to perform functions such as malloc(), write() and printf() in a way that is not (so) machine dependent, as would be using something like syscall. I have started by (first, reading the docs) and by writing simple programs in c and examining the .s files to try to tell how the code is being modified. In examination, I observe several directives (which I believe can also be called psuedo-ops) which are not part of the GAS assembler specification. So I am assuming they are coming from a library somewhere. Examples are .indirect_symbol, .lazy_symbol_pointer, .subsections_via_symbols.

    I have read that (probably on 386 PCs) for commands such as printf(), the linker links the object file output from the assembler with a ready-made object file called printf.o, and these are combined to create the executable. I have wanted to examine the files that GAS (or the linker) is using that ultimately generates the machine code that performs these functions higher level functions.

    I have searched and hacked at this for two days, and have come up with nothing. I have searched my computer for the existence of files with a .o extension, have searched for Mach-o, dylib, and there is virtually nothing on my hard drive that would appear that is being used by the compiler/assembler/linker. I really don't know what I should be looking for.

    I find text in the code such as _malloc, _write, and _printf, so I am assuming that these must be referred to in a library somewhere.

    Anyone know where to find out this information?

    Thanks, Allasso

    EDIT: I would also like to know, do functions such as write(), read(), etc ultimately use syscall by determing the syscall number of those machine functions?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    IIRC, the GNU implementation of the C standard library functions (like printf() and malloc()) is in libc.a.

    I'm not familiar with either MacOS or PPC, but you usually have a setup that goes something like:
    * OS has various IO primitives that are accessed by syscall or whatever your assembly language has to jump into kernel space.
    * Whoever writes to OS provides wrappers over this to pretty them up to be called by mortal programmers. This is where write() lives.
    * Your C compiler comes with a runtime that implements the C standard library using the system calls. This is where printf() lives.

    There exist some standards for that middle layer (like POSIX) which allow you to write a C standard library that can build against many different systems. The part that has to change with the systems is the source code of the system calls which comes with the OS.
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2010
    Posts
    17
    Rep Power
    0
    Ah, nice to hear from someone, thanks.

    So it sounds like ultimately syscall is used to do the actual work. If this is true, then the program must go through some interface with the System, since syscalls are specific to the hardware and kernel.

IMN logo majestic logo threadwatch logo seochat tools logo