1
0
mirror of https://github.com/cahirwpz/amigaos-cross-toolchain synced 2025-11-23 04:02:39 +00:00

Clean up compiler warnings and crash at link time.

This commit is contained in:
Krystian Bacławski
2012-02-16 19:08:34 -08:00
parent 8d4f789d7e
commit e2ba3b77c5
5 changed files with 209 additions and 98 deletions

View File

@ -44,17 +44,17 @@
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <stdint.h>
#include <errno.h>
#include "defs.h"
extern int errno;
static int ExeFile,NbOffs;
static int32_t *SearchOffs;
int ExeFile,NbOffs;
unsigned long *SearchOffs;
const char version_id[] = "\000$VER: GccFindHit 1.2.1 (07.12.96)";
static const char version_id[] = "\000$VER: GccFindHit 1.2.1 (07.12.96)";
int Read4 (long *buf)
int Read4 (int32_t *buf)
{
if (read (ExeFile,buf,4)==4) {
*buf = GETLONG(*buf);
@ -66,7 +66,7 @@ int Read4 (long *buf)
struct Header *ReadHeader ()
{
long nb,size;
int32_t nb,size;
struct Header *h;
int i;
@ -77,7 +77,7 @@ struct Header *ReadHeader ()
/* reads the number of hunks */
if (!Read4(&nb))
return NULL;
h = (struct Header*)malloc(sizeof(struct Header)+(nb-1)*sizeof(long));
h = (struct Header*)malloc(sizeof(struct Header)+(nb-1)*sizeof(int32_t));
if (!h)
return NULL;
h->nb_hunks = nb;
@ -91,15 +91,15 @@ struct Header *ReadHeader ()
return h;
} /* ReadHeader() */
int long_cmp (long *e1,long *e2)
int long_cmp (int32_t *e1,int32_t *e2)
{
return (*e1)<(*e2);
}
void SkipRelocation ()
{
unsigned long no; /* number of offsets */
long h; /* hunk number */
int32_t no; /* number of offsets */
int32_t h; /* hunk number */
while (Read4 (&no) && no && Read4 (&h))
lseek (ExeFile, no<<2, SEEK_CUR);
}
@ -108,8 +108,8 @@ void SkipRelocation ()
so it's useless for now */
void SkipShortRel ()
{
unsigned long no;
short h;
int32_t no;
int16_t h;
while (Read4 (&no) && no && read (ExeFile, &h, sizeof h))
lseek (ExeFile, no<<1, SEEK_CUR);
}
@ -117,7 +117,7 @@ void SkipShortRel ()
/* can be slow if I/O buffering doesn't do some read-ahead */
void SkipSymbols ()
{
long nl; /* name length in long words */
int32_t nl; /* name length in long words */
while (Read4 (&nl) && nl) {
/* skips the name + the value */
lseek (ExeFile, (nl+1)<<2, SEEK_CUR);
@ -127,12 +127,12 @@ void SkipSymbols ()
/* skip hunks such as HUNK_NAME that have their size in the first long */
void SkipHunk ()
{
unsigned long size;
int32_t size;
if (Read4 (&size))
lseek (ExeFile, size<<2, SEEK_CUR);
}
char *get_string(long offset)
char *get_string(int32_t offset)
{
static char buf[256];
@ -142,35 +142,34 @@ char *get_string(long offset)
return buf;
}
void GetLines (long symsz, BSD_SYM *syms, long string_offset)
void GetLines (int32_t symsz, BSD_SYM *syms, int32_t string_offset)
{
long nbsyms = symsz / sizeof(BSD_SYM);
int32_t nbsyms = symsz / sizeof(BSD_SYM);
BSD_SYM *sym = syms;
unsigned char prev_type;
long srcname = 0, prev_src = 0;
unsigned short prev_line = 0;
unsigned long offs , prev_offs = -1UL;
uint8_t prev_type;
int32_t srcname = 0, prev_src = 0;
uint16_t prev_line = 0;
uint32_t offs , prev_offs = -1UL;
int i;
while (nbsyms--) {
switch (sym->type) {
case N_SO:
case N_SOL:
srcname = GETLONG (sym->strx);
break;
case N_SLINE:
offs = OFFSET_N_SLINE (GETLONG (sym->value));
for (i = 0; i < NbOffs; i++) {
if (SearchOffs[i] >= prev_offs && SearchOffs[i] < offs) {
printf ("%s: line %hd, offset 0x%lx\n",
get_string(prev_src + string_offset), prev_line,
prev_offs);
}
}
prev_offs = offs;
prev_line = GETWORD (sym->desc);
prev_src = srcname;
break;
case N_SO:
case N_SOL:
srcname = GETLONG (sym->strx);
break;
case N_SLINE:
offs = OFFSET_N_SLINE (GETLONG (sym->value));
for (i = 0; i < NbOffs; i++) {
if (SearchOffs[i] >= prev_offs && SearchOffs[i] < offs) {
printf ("%s: line %hd, offset 0x%x\n", get_string(prev_src +
string_offset), prev_line, prev_offs);
}
}
prev_offs = offs;
prev_line = GETWORD (sym->desc);
prev_src = srcname;
break;
}
prev_type = sym->type;
sym++;
@ -178,18 +177,18 @@ void GetLines (long symsz, BSD_SYM *syms, long string_offset)
/* the last SLINE is a special case */
for (i = 0; i < NbOffs; i++) {
if (SearchOffs[i] == prev_offs) {
printf ("%s: line %hd, offset 0x%lx\n",
get_string(prev_src + string_offset), prev_line,
prev_offs);
printf ("%s: line %hd, offset 0x%x\n",
get_string(prev_src + string_offset), prev_line,
prev_offs);
}
}
}
void HunkDebug (void)
{
long hunksz, symsz, strsz;
int32_t hunksz, symsz, strsz;
struct bsd_header hdr;
long pos, init_pos = lseek (ExeFile, 0, SEEK_CUR);
int32_t pos, init_pos = lseek (ExeFile, 0, SEEK_CUR);
char *syms;
if (init_pos < 0)
@ -218,7 +217,7 @@ void HunkDebug (void)
void DoHunks (struct Header *h)
{
long hnum,size,nsec=0;
int32_t hnum,size,nsec=0;
while (Read4 (&hnum)) {
switch (hnum) {
case HUNK_NAME:
@ -255,7 +254,7 @@ void DoHunks (struct Header *h)
HunkDebug ();
break;
default:
fprintf (stderr, "Unexpected hunk 0x%lx\n", hnum);
fprintf (stderr, "Unexpected hunk 0x%x\n", hnum);
return;
}
}
@ -270,7 +269,7 @@ void Out(int code)
int main(int argc,char **argv)
{
long HunkNum;
int32_t HunkNum;
struct Header *header=NULL;
int i;
@ -284,13 +283,13 @@ int main(int argc,char **argv)
Out (1);
}
NbOffs = argc-2;
SearchOffs = (long*)malloc (sizeof (long)*NbOffs);
SearchOffs = (int32_t*)malloc (sizeof (int32_t)*NbOffs);
if (!SearchOffs) {
fprintf (stderr,"No memory\n");
Out (1);
}
for (i=0; i<NbOffs; i++) {
if (sscanf (argv[i+2],"%lx",&SearchOffs[i])!=1) {
if (sscanf (argv[i+2],"%x",&SearchOffs[i])!=1) {
fprintf (stderr, "Operand %s is not an hex offset\n", argv[i+2]);
Out (1);
}

View File

@ -1,9 +1,14 @@
CC = gcc
CFLAGS = -O2 -Wall -I../target/include -I../target/m68k-amigaos/sys-include
CFLAGS = -O2 -Wall -I../target/include
all: GccFindHit hunk2aout
BINS = GccFindHit hunk2aout
all: $(BINS)
GccFindHit.o: GccFindHit.c defs.h
hunk2aout.o: hunk2aout.c
hunk2aout.o: hunk2aout.c a.out.h
clean: GccFindHit hunk2aout
clean:
rm -f $(BINS) *.o *~
# vim: set noexpandtab ts=8 sw=8 :

109
tools/a.out.h Normal file
View File

@ -0,0 +1,109 @@
#ifndef _AOUT_H_
#define _AOUT_H_
#include <stdint.h>
/* Header prepended to each a.out file. */
struct exec {
uint16_t a_mid; /* machine ID */
uint16_t a_magic; /* magic number */
uint32_t a_text; /* text segment size */
uint32_t a_data; /* initialized data size */
uint32_t a_bss; /* uninitialized data size */
uint32_t a_syms; /* symbol table size */
uint32_t a_entry; /* entry point */
uint32_t a_trsize; /* text relocation size */
uint32_t a_drsize; /* data relocation size */
};
/* a_magic */
#define OMAGIC 0407 /* old impure format */
#define NMAGIC 0410 /* read-only text */
#define ZMAGIC 0413 /* demand load format */
/* a_mid */
#define MID_ZERO 0 /* unknown - implementation dependent */
#define MID_SUN010 1 /* sun 68010/68020 binary */
#define MID_SUN020 2 /* sun 68020-only binary */
#define MID_HP200 200 /* hp200 (68010) BSD binary */
#define MID_HP300 300 /* hp300 (68020+68881) BSD binary */
#define MID_HPUX 0x20C /* hp200/300 HP-UX binary */
#define MID_HPUX800 0x20B /* hp800 HP-UX binary */
#define __LDPGSZ 8192
/* Valid magic number check. */
#define N_BADMAG(ex) \
((ex).a_magic != NMAGIC && (ex).a_magic != OMAGIC && \
(ex).a_magic != ZMAGIC)
/* Address of the bottom of the text segment. */
#define N_TXTADDR(ex) ((ex).a_magic == ZMAGIC ? __LDPGSZ : 0)
/* Address of the bottom of the data segment. */
#define N_DATADDR(ex) \
(N_TXTADDR(ex) + ((ex).a_magic == OMAGIC ? (ex).a_text \
: __LDPGSZ + ((ex).a_text - 1 & ~(__LDPGSZ - 1))))
#define N_BSSADDR(ex) (N_DATADDR(ex)+(ex).a_data)
/* Text segment offset. */
#define N_TXTOFF(ex) \
((ex).a_magic == ZMAGIC ? 0 : sizeof(struct exec))
/* Data segment offset. */
#define N_DATOFF(ex) \
(N_TXTOFF(ex) + ((ex).a_magic != ZMAGIC ? (ex).a_text \
: __LDPGSZ + ((ex).a_text - 1 & ~(__LDPGSZ - 1))))
/* Symbol table offset. */
#define N_SYMOFF(ex) \
(N_TXTOFF(ex) + (ex).a_text + (ex).a_data + (ex).a_trsize + \
(ex).a_drsize)
/* String table offset. */
#define N_STROFF(ex) (N_SYMOFF(ex) + (ex).a_syms)
/* Relocation format. */
struct relocation_info {
int r_address; /* offset in text or data segment */
unsigned int r_symbolnum : 24, /* ordinal number of add symbol */
r_pcrel : 1, /* 1 if value should be pc-relative */
r_length : 2, /* log base 2 of value's width */
r_extern : 1, /* 1 if need to add symbol to value */
r_baserel : 1, /* 1 if linkage table relative */
r_jmptable : 1, /* 1 if pc-relative to jump table */
: 2; /* reserved */
};
/*
* Symbol table entry format.
*/
#define N_UNDF 0x00 /* undefined */
#define N_ABS 0x02 /* absolute address */
#define N_TEXT 0x04 /* text segment */
#define N_DATA 0x06 /* data segment */
#define N_BSS 0x08 /* bss segment */
#define N_INDR 0x0a /* alias definition */
#define N_SIZE 0x0c /* pseudo type, defines a symbol's size */
#define N_COMM 0x12 /* common reference */
#define N_FN 0x1e /* file name (N_EXT on) */
#define N_WARN 0x1e /* warning message (N_EXT off) */
#define N_EXT 0x01 /* external (global) bit, OR'ed in */
#define N_TYPE 0x1e /* mask for all the type bits */
#define N_STAB 0x0e0 /* mask for debugger symbols -- stab(5) */
struct nlist {
union {
char *n_name; /* symbol name (in memory) */
int32_t n_strx; /* file string table offset (on disk) */
} n_un;
uint8_t n_type; /* type defines */
int8_t n_other; /* spare */
int16_t n_desc; /* used by stab entries */
uint32_t n_value; /* address/value of the symbol */
};
#endif /* !_AOUT_H_ */

View File

@ -56,24 +56,24 @@ enum {
/* amigaos hunk header structure */
struct Header {
long nb_hunks;
long first;
long last;
long sizes[1];
int32_t nb_hunks;
int32_t first;
int32_t last;
int32_t sizes[1];
};
/* bsd header structure */
struct bsd_header{
long magic;
long symsz;
long strsz;
int32_t magic;
int32_t symsz;
int32_t strsz;
};
typedef struct {
long strx;
unsigned char type;
unsigned char other;
unsigned short desc;
long value;
int32_t strx;
uint8_t type;
uint8_t other;
uint16_t desc;
int32_t value;
} BSD_SYM;

View File

@ -42,13 +42,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#ifdef i386
#undef i386
#include <a.out.h>
#define i386
#else
#include <a.out.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -56,6 +49,8 @@
#include <stdint.h>
#include <errno.h>
#include "a.out.h"
/* This is really <dos/doshunks.h>, which is a 2.0 header file.
* You can get those 2.0 headers from CATS.
* Sorry, I'm not allowed to include them here. You may as well take the
@ -81,7 +76,7 @@
#define DP(a)
#endif
static char *version_tag = "\0$VER: hunk2aout 2.0 (1.3.97)\r\n";
char *version_tag = "\0$VER: hunk2aout 2.0 (1.3.97)\r\n";
static uint32_t *file_buf = 0;
@ -117,18 +112,20 @@ struct table {
int max_el;
};
void emit_aout_file (int fd, void *text, void *data, void *chip_data,
struct exec *hdr, int chip_data_size, int chip_bss_size,
struct table *ch_tab, struct table *dh_tab, struct table *bh_tab,
struct table *cdh_tab, struct table *cbh_tab,
struct table *reloc_tab, struct table *symbol_tab, int max_hunk);
static void emit_aout_file(int fd, void *text, void *data, void *chip_data,
struct exec *hdr, int chip_data_size,
int chip_bss_size, struct table *ch_tab,
struct table *dh_tab, struct table *bh_tab,
struct table *cdh_tab, struct table *cbh_tab,
struct table *reloc_tab, struct table *symbol_tab,
int max_hunk);
#define TAB_START_SIZE 1024
/* advance the hunk-pointer to the next hunk. Assumes the hunk-pointer is
* pointing at the length-field currently
*/
static void inline next_hunk(uint32_t **hp)
static void next_hunk(uint32_t **hp)
{
/* skip over the length field and the there given length */
*hp += 1 + **hp;
@ -136,7 +133,7 @@ static void inline next_hunk(uint32_t **hp)
/* save a lot of space for duplicate string, that all say "only.. with size.. */
static void inline limit_hunk (char *hunk_name)
static void limit_hunk (char *hunk_name)
{
fprintf (stderr, "only one %s hunk with size!=0 supported.\n", hunk_name);
}
@ -148,10 +145,10 @@ static void inline limit_hunk (char *hunk_name)
* don't need the whole functionality of an obstack, so I kept it simple ;-))
* Only use the offset, since the table itself may be reallocated.
*/
char *str_table = 0;
int strtab_size, strtab_index;
static char *str_table = 0;
static int strtab_size, strtab_index;
static int inline stralloc (int len)
static int stralloc (int len)
{
int res;
@ -178,15 +175,14 @@ static int inline stralloc (int len)
return res;
}
static void inline
strfree (int str)
static void strfree (int str)
{
strtab_index = str;
}
/****************************************************************************/
static void inline add_table (struct table *tab, void *el)
static void add_table (struct table *tab, void *el)
{
if (tab->i == tab->max_el)
{
@ -210,8 +206,8 @@ static void inline add_table (struct table *tab, void *el)
bcopy (el, (uint8_t *)tab->base + (tab->i++ * tab->el_size), tab->el_size);
}
static void inline add_reloc (struct table *tab, int from, int to, int offset,
int size, int pcrel, int baserel, int sym_num)
static void add_reloc (struct table *tab, int from, int to, int offset,
int size, int pcrel, int baserel, int sym_num)
{
struct reloc r;
@ -228,8 +224,8 @@ static void inline add_reloc (struct table *tab, int from, int to, int offset,
add_table (tab, &r);
}
static void inline add_symbol (struct table *tab, int num, uint32_t type,
int value, char *name)
static void add_symbol (struct table *tab, int num, uint32_t type,
int value, char *name)
{
struct symbol s;
@ -267,7 +263,7 @@ static void inline add_symbol (struct table *tab, int num, uint32_t type,
/****************************************************************************/
void digest_objfile (uint32_t **file_pptr, uint32_t *max_fp)
static void digest_objfile (uint32_t **file_pptr, uint32_t *max_fp)
{
/* this makes it less clumsy.. */
uint32_t *file_ptr = *file_pptr;
@ -601,11 +597,13 @@ void digest_objfile (uint32_t **file_pptr, uint32_t *max_fp)
}
void emit_aout_file (int fd, void *text, void *data, void *chip_data,
struct exec *hdr, int chip_data_size, int chip_bss_size,
struct table *ch_tab, struct table *dh_tab, struct table *bh_tab,
struct table *cdh_tab, struct table *cbh_tab,
struct table *reloc_tab, struct table *symbol_tab, int max_hunk)
static void emit_aout_file (int fd, void *text, void *data, void *chip_data,
struct exec *hdr, int chip_data_size,
int chip_bss_size, struct table *ch_tab,
struct table *dh_tab, struct table *bh_tab,
struct table *cdh_tab, struct table *cbh_tab,
struct table *reloc_tab, struct table *symbol_tab,
int max_hunk)
{
int *code_hunks = ch_tab->base;
int *data_hunks = dh_tab->base;
@ -659,9 +657,9 @@ void emit_aout_file (int fd, void *text, void *data, void *chip_data,
if (r->to_hunk > -1)
{
/* the base address of the used source hunk */
void *base_hunk;
void *base_hunk = NULL;
/* this is the mentioned hunk-gap */
uint32_t offset;
uint32_t offset = 0;
switch (htype[r->from_hunk])
{