Assembler as shared library

Philip Herron redbrain@gcc.gnu.org
Mon Feb 17 16:54:00 GMT 2014


Hey all

This is my initial patch it creates a shared library out of gas and
installs the necessary headers along side it. I am trying to work out
how to use it so far need more time tracing through the code to figure
it out but so far i am been copying and pasting bits and pieces to get
this so far as a client program:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <as.h>
#include <subsegs.h>
#include <output-file.h>

char * out_file_name;

int main (int argc, char **argv)
{
    printf ("trying...\n");
    out_file_name = strdup ("./ninja");

    bfd_init ();
    md_begin ();

    symbol_begin ();
    frag_init ();
    subsegs_begin ();
    read_begin ();
    input_scrub_begin ();
    expr_begin ();

    output_file_create (out_file_name);

    dot_symbol_init ();

    text_section = subseg_new (TEXT_SECTION_NAME, 0);
    data_section = subseg_new (DATA_SECTION_NAME, 0);
    bss_section = subseg_new (BSS_SECTION_NAME, 0);

    subseg_new (BFD_ABS_SECTION_NAME, 0);
    subseg_new (BFD_UND_SECTION_NAME, 0);
    reg_section = subseg_new ("*GAS `reg' section*", 0);
    expr_section = subseg_new ("*GAS `expr' section*", 0);
    subseg_set (text_section, 0);

    read_a_source_file ("./t.s");
    write_object_file ();

    free (out_file_name);

    return 0;
}

$ gcc -g -O2 -Wall test.c -o test -I/opt/binutils/include
-L/opt/binutils/lib -lgas -lbfd

Its definitely not right but demonstrates i am calling into normal gas
things. Hope to get more working soon and i will probably need to make
some wrapper code as this although i am doing it completely wrong is
fairly involved. I would great if i could get some feedback i reckon
this patch is probably going to break some stuff.

Thanks i hope i can get something more use-able soon.

--Phil

On 14 February 2014 17:06, Philip Herron <redbrain@gcc.gnu.org> wrote:
> Ah thanks! I have a github repo:
>
> https://github.com/redbrain/binutils-gdb/tree/libasm
>
> It now builds libasm.la which as is built off now and as seems to
> work. So i think i have the first stages of this working. I am
> #ifdefing out the main so far and need to make a libgas.h so we can
> use this in David Malcoms jit.
>
> On 14 February 2014 15:13, nick clifton <nickc@redhat.com> wrote:
>> Hi Philip,
>>
>>
>>> But i can find any where to start to make a little mini assembler
>>> using libopcodes.
>>
>>
>> Take a look at gas/doc/internals.texi, especially the section on GAS
>> processing.
>>
>> Essentially you will need to provide library routines that emulate what is
>> done in gas/as.c:main().
>>
>> Cheers
>>   Nick
>>
>>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Initial-libasm.la-as.c-links-of-this-convience-lib-a.patch
Type: text/x-patch
Size: 214572 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20140217/c79a97a5/attachment.bin>


More information about the Binutils mailing list