libyasm
Data Structures | Defines | Typedefs | Functions

libyasm/section.h File Reference

YASM section interface. More...

Go to the source code of this file.

Data Structures

struct  yasm_reloc
struct  yasm_object
 An object. More...

Typedefs

typedef struct yasm_reloc yasm_reloc
 Basic YASM relocation.

Functions

YASM_LIB_DECL yasm_objectyasm_object_create (const char *src_filename, const char *obj_filename, yasm_arch *arch, const yasm_objfmt_module *objfmt_module, const yasm_dbgfmt_module *dbgfmt_module)
 Create a new object.
YASM_LIB_DECL yasm_sectionyasm_object_get_general (yasm_object *object, const char *name, unsigned long align, int code, int res_only, int *isnew, unsigned long line)
 Create a new, or continue an existing, general section.
YASM_LIB_DECL int yasm_object_directive (yasm_object *object, const char *name, const char *parser, yasm_valparamhead *valparams, yasm_valparamhead *objext_valparams, unsigned long line)
 Handle a directive.
YASM_LIB_DECL void yasm_object_destroy (yasm_object *object)
 Delete (free allocated memory for) an object.
YASM_LIB_DECL void yasm_object_print (const yasm_object *object, FILE *f, int indent_level)
 Print an object.
YASM_LIB_DECL void yasm_object_finalize (yasm_object *object, yasm_errwarns *errwarns)
 Finalize an object after parsing.
YASM_LIB_DECL int yasm_object_sections_traverse (yasm_object *object, void *d, int(*func)(yasm_section *sect, void *d))
 Traverses all sections in an object, calling a function on each section.
YASM_LIB_DECL yasm_sectionyasm_object_find_general (yasm_object *object, const char *name)
 Find a general section in an object, based on its name.
YASM_LIB_DECL void yasm_object_set_source_fn (yasm_object *object, const char *src_filename)
 Change the source filename for an object.
YASM_LIB_DECL void yasm_object_set_global_prefix (yasm_object *object, const char *prefix)
 Change the prefix used for externally-visible symbols.
YASM_LIB_DECL void yasm_object_set_global_suffix (yasm_object *object, const char *suffix)
 Change the suffix used for externally-visible symbols.
YASM_LIB_DECL void yasm_object_optimize (yasm_object *object, yasm_errwarns *errwarns)
 Optimize an object.
YASM_LIB_DECL int yasm_section_is_code (yasm_section *sect)
 Determine if a section is flagged to contain code.
YASM_LIB_DECL unsigned long yasm_section_get_opt_flags (const yasm_section *sect)
 Get yasm_optimizer-specific flags.
YASM_LIB_DECL void yasm_section_set_opt_flags (yasm_section *sect, unsigned long opt_flags)
 Set yasm_optimizer-specific flags.
YASM_LIB_DECL int yasm_section_is_default (const yasm_section *sect)
 Determine if a section was declared as the "default" section (e.g.
YASM_LIB_DECL void yasm_section_set_default (yasm_section *sect, int def)
 Set section "default" flag to a new value.
YASM_LIB_DECL yasm_objectyasm_section_get_object (const yasm_section *sect)
 Get object owner of a section.
YASM_LIB_DECL void * yasm_section_get_data (yasm_section *sect, const yasm_assoc_data_callback *callback)
 Get assocated data for a section and data callback.
YASM_LIB_DECL void yasm_section_add_data (yasm_section *sect, const yasm_assoc_data_callback *callback, void *data)
 Add associated data to a section.
YASM_LIB_DECL void yasm_section_add_reloc (yasm_section *sect, yasm_reloc *reloc, void(*destroy_func)(void *reloc))
 Add a relocation to a section.
YASM_LIB_DECL yasm_relocyasm_section_relocs_first (yasm_section *sect)
 Get the first relocation for a section.
yasm_relocyasm_section_reloc_next (yasm_reloc *reloc)
 Get the next relocation for a section.
YASM_LIB_DECL void yasm_reloc_get (yasm_reloc *reloc, yasm_intnum **addrp, yasm_symrec **symp)
 Get the basic relocation information for a relocation.
YASM_LIB_DECL yasm_bytecodeyasm_section_bcs_first (yasm_section *sect)
 Get the first bytecode in a section.
YASM_LIB_DECL yasm_bytecodeyasm_section_bcs_last (yasm_section *sect)
 Get the last bytecode in a section.
YASM_LIB_DECL yasm_bytecodeyasm_section_bcs_append (yasm_section *sect, yasm_bytecode *bc)
 Add bytecode to the end of a section.
YASM_LIB_DECL int yasm_section_bcs_traverse (yasm_section *sect, yasm_errwarns *errwarns, void *d, int(*func)(yasm_bytecode *bc, void *d))
 Traverses all bytecodes in a section, calling a function on each bytecode.
YASM_LIB_DECL const char * yasm_section_get_name (const yasm_section *sect)
 Get name of a section.
YASM_LIB_DECL void yasm_section_set_align (yasm_section *sect, unsigned long align, unsigned long line)
 Change alignment of a section.
YASM_LIB_DECL unsigned long yasm_section_get_align (const yasm_section *sect)
 Get alignment of a section.
YASM_LIB_DECL void yasm_section_print (const yasm_section *sect, FILE *f, int indent_level, int print_bcs)
 Print a section.

Detailed Description

YASM section interface.

Definition in file section.h.


Typedef Documentation

typedef struct yasm_reloc yasm_reloc

Basic YASM relocation.

Object formats will need to extend this structure with additional fields for relocation type, etc.

Definition at line 40 of file section.h.


Function Documentation

YASM_LIB_DECL yasm_object* yasm_object_create ( const char *  src_filename,
const char *  obj_filename,
yasm_arch arch,
const yasm_objfmt_module objfmt_module,
const yasm_dbgfmt_module dbgfmt_module 
)

Create a new object.

A default section is created as the first section. An empty symbol table (yasm_symtab) and line mapping (yasm_linemap) are automatically created.

Parameters:
src_filenamesource filename (e.g. "file.asm")
obj_filenameobject filename (e.g. "file.o")
archarchitecture
objfmt_moduleobject format module
dbgfmt_moduledebug format module
Returns:
Newly allocated object, or NULL on error.
YASM_LIB_DECL void yasm_object_destroy ( yasm_object object)

Delete (free allocated memory for) an object.

All sections in the object and all bytecodes within those sections are also deleted.

Parameters:
objectobject
YASM_LIB_DECL int yasm_object_directive ( yasm_object object,
const char *  name,
const char *  parser,
yasm_valparamhead valparams,
yasm_valparamhead objext_valparams,
unsigned long  line 
)

Handle a directive.

Passed down to object format, debug format, or architecture as appropriate.

Parameters:
objectobject
namedirective name
parserparser keyword
valparamsvalue/parameters
objext_valparams"object format-specific" value/parameters
linevirtual line (from yasm_linemap)
Returns:
0 if directive recognized, nonzero if unrecognized.
YASM_LIB_DECL void yasm_object_finalize ( yasm_object object,
yasm_errwarns errwarns 
)

Finalize an object after parsing.

Parameters:
objectobject
errwarnserror/warning set
Note:
Errors/warnings are stored into errwarns.
YASM_LIB_DECL yasm_section* yasm_object_find_general ( yasm_object object,
const char *  name 
)

Find a general section in an object, based on its name.

Parameters:
objectobject
namesection name
Returns:
Section matching name, or NULL if no match found.
YASM_LIB_DECL yasm_section* yasm_object_get_general ( yasm_object object,
const char *  name,
unsigned long  align,
int  code,
int  res_only,
int *  isnew,
unsigned long  line 
)

Create a new, or continue an existing, general section.

The section is added to the object if there's not already a section by that name.

Parameters:
objectobject
namesection name
alignalignment in bytes (0 if none)
codeif nonzero, section is intended to contain code (e.g. alignment should be made with NOP instructions, not 0)
res_onlyif nonzero, only space-reserving bytecodes are allowed in the section (ignored if section already exists)
isnewoutput; set to nonzero if section did not already exist
linevirtual line of section declaration (ignored if section already exists)
Returns:
New section.
YASM_LIB_DECL void yasm_object_optimize ( yasm_object object,
yasm_errwarns errwarns 
)

Optimize an object.

Takes the unoptimized object and optimizes it. If successful, the object is ready for output to an object file.

Parameters:
objectobject
errwarnserror/warning set
Note:
Optimization failures are stored into errwarns.
YASM_LIB_DECL void yasm_object_print ( const yasm_object object,
FILE *  f,
int  indent_level 
)

Print an object.

For debugging purposes.

Parameters:
objectobject
ffile
indent_levelindentation level
YASM_LIB_DECL int yasm_object_sections_traverse ( yasm_object object,
void *  d,
int(*)(yasm_section *sect, void *d)  func 
)

Traverses all sections in an object, calling a function on each section.

Parameters:
objectobject
ddata pointer passed to func on each call
funcfunction
Returns:
Stops early (and returns func's return value) if func returns a nonzero value; otherwise 0.
YASM_LIB_DECL void yasm_object_set_global_prefix ( yasm_object object,
const char *  prefix 
)

Change the prefix used for externally-visible symbols.

Parameters:
objectobject
prefixnew prefix
YASM_LIB_DECL void yasm_object_set_global_suffix ( yasm_object object,
const char *  suffix 
)

Change the suffix used for externally-visible symbols.

Parameters:
objectobject
suffixnew suffix
YASM_LIB_DECL void yasm_object_set_source_fn ( yasm_object object,
const char *  src_filename 
)

Change the source filename for an object.

Parameters:
objectobject
src_filenamenew source filename (e.g. "file.asm")
YASM_LIB_DECL void yasm_reloc_get ( yasm_reloc reloc,
yasm_intnum **  addrp,
yasm_symrec **  symp 
)

Get the basic relocation information for a relocation.

Parameters:
relocrelocation
addrpaddress of relocation within section (returned)
symprelocated symbol (returned)
YASM_LIB_DECL void yasm_section_add_data ( yasm_section sect,
const yasm_assoc_data_callback callback,
void *  data 
)

Add associated data to a section.

Attention:
Deletes any existing associated data for that data callback.
Parameters:
sectsection
callbackcallback
datadata to associate
YASM_LIB_DECL void yasm_section_add_reloc ( yasm_section sect,
yasm_reloc reloc,
void(*)(void *reloc)  destroy_func 
)

Add a relocation to a section.

Parameters:
sectsection
relocrelocation
destroy_funcfunction that can destroy the relocation
Note:
Does not make a copy of reloc. The same destroy_func must be used for all relocations in a section or an internal error will occur. The section will destroy the relocation address; it is the caller's responsibility to destroy any other allocated data.
YASM_LIB_DECL yasm_bytecode* yasm_section_bcs_append ( yasm_section sect,
yasm_bytecode bc 
)

Add bytecode to the end of a section.

Note:
Does not make a copy of bc; so don't pass this function static or local variables, and discard the bc pointer after calling this function.
Parameters:
sectsection
bcbytecode (may be NULL)
Returns:
If bytecode was actually appended (it wasn't NULL or empty), the bytecode; otherwise NULL.
YASM_LIB_DECL yasm_bytecode* yasm_section_bcs_first ( yasm_section sect)

Get the first bytecode in a section.

Parameters:
sectsection
Returns:
First bytecode in section (at least one empty bytecode is always present).
YASM_LIB_DECL yasm_bytecode* yasm_section_bcs_last ( yasm_section sect)

Get the last bytecode in a section.

Parameters:
sectsection
Returns:
Last bytecode in section (at least one empty bytecode is always present).
YASM_LIB_DECL int yasm_section_bcs_traverse ( yasm_section sect,
yasm_errwarns errwarns,
void *  d,
int(*)(yasm_bytecode *bc, void *d)  func 
)

Traverses all bytecodes in a section, calling a function on each bytecode.

Parameters:
sectsection
errwarnserror/warning set (may be NULL)
ddata pointer passed to func on each call (may be NULL)
funcfunction
Returns:
Stops early (and returns func's return value) if func returns a nonzero value; otherwise 0.
Note:
If errwarns is non-NULL, yasm_errwarn_propagate() is called after each call to func (with the bytecode's line number).
YASM_LIB_DECL unsigned long yasm_section_get_align ( const yasm_section sect)

Get alignment of a section.

Parameters:
sectsection
Returns:
Alignment in bytes (0 if none).
YASM_LIB_DECL void* yasm_section_get_data ( yasm_section sect,
const yasm_assoc_data_callback callback 
)

Get assocated data for a section and data callback.

Parameters:
sectsection
callbackcallback used when adding data
Returns:
Associated data (NULL if none).
YASM_LIB_DECL const char* yasm_section_get_name ( const yasm_section sect)

Get name of a section.

Parameters:
sectsection
Returns:
Section name.
YASM_LIB_DECL yasm_object* yasm_section_get_object ( const yasm_section sect)

Get object owner of a section.

Parameters:
sectsection
Returns:
Object this section is a part of.
YASM_LIB_DECL unsigned long yasm_section_get_opt_flags ( const yasm_section sect)

Get yasm_optimizer-specific flags.

For yasm_optimizer use only.

Parameters:
sectsection
Returns:
Optimizer-specific flags.
YASM_LIB_DECL int yasm_section_is_code ( yasm_section sect)

Determine if a section is flagged to contain code.

Parameters:
sectsection
Returns:
Nonzero if section is flagged to contain code.
YASM_LIB_DECL int yasm_section_is_default ( const yasm_section sect)

Determine if a section was declared as the "default" section (e.g.

not created through a section directive).

Parameters:
sectsection
Returns:
Nonzero if section was declared as default.
YASM_LIB_DECL void yasm_section_print ( const yasm_section sect,
FILE *  f,
int  indent_level,
int  print_bcs 
)

Print a section.

For debugging purposes.

Parameters:
ffile
indent_levelindentation level
sectsection
print_bcsif nonzero, print bytecodes within section
yasm_reloc* yasm_section_reloc_next ( yasm_reloc reloc)

Get the next relocation for a section.

Parameters:
relocprevious relocation
Returns:
Next relocation for section. NULL if no more relocations.
YASM_LIB_DECL yasm_reloc* yasm_section_relocs_first ( yasm_section sect)

Get the first relocation for a section.

Parameters:
sectsection
Returns:
First relocation for section. NULL if no relocations.
YASM_LIB_DECL void yasm_section_set_align ( yasm_section sect,
unsigned long  align,
unsigned long  line 
)

Change alignment of a section.

Parameters:
sectsection
alignalignment in bytes
linevirtual line
YASM_LIB_DECL void yasm_section_set_default ( yasm_section sect,
int  def 
)

Set section "default" flag to a new value.

Parameters:
sectsection
defnew value of default flag
YASM_LIB_DECL void yasm_section_set_opt_flags ( yasm_section sect,
unsigned long  opt_flags 
)

Set yasm_optimizer-specific flags.

For yasm_optimizer use only.

Parameters:
sectsection
opt_flagsoptimizer-specific flags.