Skip to content

Commit

Permalink
more -Wconversion in bfd/elf*.c
Browse files Browse the repository at this point in the history
Change-Id: I7231e94b3e863c9648df3b416b4e17e4ff9bf088
  • Loading branch information
cooljeanius committed Jan 8, 2024
1 parent df4d19f commit 770f324
Show file tree
Hide file tree
Showing 16 changed files with 276 additions and 273 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/apple-gdb-1824-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ jobs:
- run: ./configure --enable-silent-rules CC=${{ matrix.compiler }} OBJC=${{ matrix.compiler }}
- run: make -ki -C libcheckpoint || make -ki -C libcheckpoint -f Makefile_orig || make -ki -C macsbug || make -ki -C macsbug/gdb_plugin_support || (if test -x "$(which ant)"; then ant; else echo "ant missing"; fi)
- run: if test ! -e libcheckpoint/libcheckpoint.dylib; then (sync && echo "ensuring libcheckpoint is built" && sync && make -ki -C libcheckpoint -f Makefile_orig RC_CFLAGS="-std=gnu89 -w -Wno-error" && sync) || (sync && make -ki -C macsbug) || (sync && make -ki -C macsbug/gdb_plugin_support) || (if test -x "$(which ant)"; then ant; else echo "ant missing"; fi); else (sync && stat libcheckpoint/libcheckpoint.dylib); fi
- run: if test -d .. && test -w .. && test ! -e ../gdb; then (echo "symlinking source directory" && pushd .. && ln -sv apple-gdb-1824 gdb && sync && readlink gdb && sync && popd); else (sync && stat .. && ls ..); fi
- run: if test -d .. && test -w .. && test ! -e ../gdb; then (echo "symlinking source directory" && pushd .. && sync && ln -sv apple-gdb-1824 gdb && sync && readlink gdb && sync && popd); else (sync && stat .. && ls ..); fi
- run: (if test -n "$(type ant 2>/dev/null)" && test -x "$(which ant)" && test -r build.xml; then if test ! -d build; then mkdir build; elif test ! -d "${HOME}"/work/apple-gdb-1824/build; then mkdir -pv "${HOME}"/work/apple-gdb-1824/build; fi; ant; else (echo "ant missing" && sync); fi) || (if test -x ./gradlew; then (./gradlew build || ./gradlew assemble || ./gradlew); elif test -r ./gradlew; then sh ./gradlew; elif test -e ./gradlew; then stat ./gradlew; else echo "gradlewrapper missing"; fi) || (if test -x "$(which gradle)"; then gradle; else echo "gradle missing"; fi) || (if test -x ~rc/bin/buildit; then sudo ~rc/bin/buildit "$(pwd)" -arch ppc -arch i386 -arch armv5 -target cross -project gdb -release RELEASENAME RC_CROSS_ARCHS=armv6; else echo "buildit missing"; fi) || ls
- run: (if test -x ./gradlew; then (./gradlew build || ./gradlew assemble || ./gradlew); elif test -r ./gradlew; then sh ./gradlew; elif test -e ./gradlew; then stat ./gradlew; else echo "gradlewrapper missing" >&2; fi) || (if test -x "$(which gradle)"; then gradle; else echo "gradle missing"; fi) || (if test -x ~rc/bin/buildit; then sudo ~rc/bin/buildit "$(pwd)" -arch ppc -arch i386 -arch armv5 -target cross -project gdb -release RELEASENAME RC_CROSS_ARCHS=armv6; else echo "buildit missing"; fi) || ls
- run: cd src && ./configure --disable-werror --disable-opts-test --enable-carbon-framework --enable-debug-symbols-framework --enable-64-bit-bfd --enable-silent-rules CC=${{ matrix.compiler }} OBJC=${{ matrix.compiler }}
- run: cd src && make configure-bfd
- run: cd src && make -C bfd headers
- run: cd src && sync && make -C bfd headers && sync
- run: cd src && if test ! -e bfd/bfd.h; then (sync && make -C bfd bfd.h); else (sync && stat bfd/bfd.h); fi
- run: cd src && make -C bfd diststuff
- run: cd src && make all-bfd
Expand All @@ -54,20 +54,20 @@ jobs:
echo "make my_arparse.h"; \
make my_arparse.h; \
else \
sync && stat arparse.h; \
sync && echo "arparse.h exists" && sync && stat arparse.h; \
fi
if test ! -f arparse.h; then \
echo "remake arparse.c"; \
remake arparse.c; \
else \
sync && wc -l arparse.h; \
sync && echo "checking arparse.h length" && sync && wc -l arparse.h; \
fi
# shellcheck disable=SC2046
if test ! -e arparse.h; then \
echo "trying the relevant Makefile rule as copied into this CI workflow"; \
/bin/sh ./../ylwrap arparse.y y.tab.c arparse.c y.tab.h "$(echo arparse.c | sed -e s/cc$/hh/ -e s/cpp$/hpp/ -e s/cxx$/hxx/ -e s/c++$/h++/ -e s/c$/h/)" y.output arparse.output -- $(if [ -f ../bison/bison ]; then echo ../bison/bison -y -L./../bison/; else echo bison -o y.tab.c; fi) -d -t -v -k; \
else \
sync && du arparse.h; \
sync && echo "checking arparse.h disk usage" && sync && du arparse.h; \
fi
if test -e arparse.h; then \
if test ! -e ../bfd/arparse.h; then \
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
- run: cd src && make check-opcodes && sync && make check-intl
- run: cd src && make check-binutils
- run: cd src && make check-utils
- run: time (pwd && sync && ls)
- run: time (pwd && sync && ls && sync)
if: "${{ success() }}"
- name: Upload a Build Artifact
uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
else \
(sync && stat /home/runner/work/apple-gdb-1824/build); \
fi
(cd src && sync && echo "now in $(pwd)...")
(cd src && sync && echo "now in $(pwd)..." && sync)
- name: Dependencies
if: matrix.language == 'c-cpp'
Expand Down
1 change: 1 addition & 0 deletions macsbug/gdb_plugin_support/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ install : all $(DSTDIR)

$(SYMROOT)/gdb_plugin_support.o : $(OBJS)
ld -r $(OBJS) -arch $(TARGET_ARCHITECTURE) -o $(SYMROOT)/gdb_plugin_support.o
if test -d $(SYMROOT); then stat $(SYMROOT)/gdb_plugin_support.o; fi

$(OFILE_DIR)/%.o : %.c $(HFILES)
$(CC) $(CFLAGS) $(RC_CFLAGS) -o $(OFILE_DIR)/$(notdir $*).o $<
Expand Down
21 changes: 11 additions & 10 deletions src/bfd/elf-nacl.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ segment_eligible_for_headers (struct elf_segment_map *seg,
return FALSE;
for (i = 0; i < seg->count; ++i)
{
if ((seg->sections[i]->flags & (SEC_CODE|SEC_READONLY)) != SEC_READONLY)
if ((seg->sections[i]->flags & (SEC_CODE | SEC_READONLY)) != SEC_READONLY)
return FALSE;
}
return TRUE;
Expand All @@ -68,14 +68,15 @@ segment_eligible_for_headers (struct elf_segment_map *seg,
The first non-executable PT_LOAD segment appears first in the file
and contains the ELF file header and phdrs. */
bfd_boolean
nacl_modify_segment_map (bfd *abfd, struct bfd_link_info *info)
nacl_modify_segment_map(bfd *abfd, struct bfd_link_info *info)
{
struct elf_segment_map **m = &elf_seg_map (abfd);
struct elf_segment_map **m = &elf_seg_map(abfd);
struct elf_segment_map **first_load = NULL;
struct elf_segment_map **last_load = NULL;
bfd_boolean moved_headers = FALSE;
int sizeof_headers = info == NULL ? 0 : bfd_sizeof_headers (abfd, info);
bfd_vma minpagesize = get_elf_backend_data (abfd)->minpagesize;
int sizeof_headers = ((info == NULL)
? 0 : bfd_sizeof_headers(abfd, info));
bfd_vma minpagesize = get_elf_backend_data(abfd)->minpagesize;

if (info != NULL && info->user_phdrs)
/* The linker script used PHDRS explicitly, so don't change what the
Expand All @@ -88,15 +89,15 @@ nacl_modify_segment_map (bfd *abfd, struct bfd_link_info *info)

if (seg->p_type == PT_LOAD)
{
bfd_boolean executable = segment_executable (seg);
bfd_boolean executable = segment_executable(seg);

if (executable
&& seg->count > 0
&& seg->sections[0]->vma % minpagesize == 0)
&& (seg->count > 0)
&& ((seg->sections[0]->vma % minpagesize) == 0))
{
asection *lastsec = seg->sections[seg->count - 1];
bfd_vma end = lastsec->vma + lastsec->size;
if (end % minpagesize != 0)
bfd_vma end = (lastsec->vma + lastsec->size);
if ((end % minpagesize) != 0)
{
/* This is an executable segment that starts on a page
boundary but does not end on a page boundary. Fill
Expand Down
2 changes: 1 addition & 1 deletion src/bfd/elf-strtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ _bfd_elf_strtab_add(struct elf_strtab_hash *tab, const char *str,
entry->refcount++;
if (entry->len == 0)
{
entry->len = (strlen(str) + 1UL);
entry->len = (int)(strlen(str) + 1UL);
/* 2G strings lose: */
BFD_ASSERT(entry->len > 0);
if (tab->size == tab->alloced)
Expand Down
74 changes: 38 additions & 36 deletions src/bfd/elf32-avr.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,66 +784,68 @@ elf32_avr_relocate_section(bfd *output_bfd ATTRIBUTE_UNUSED,
Elf_Internal_Sym *local_syms,
asection **local_sections)
{
Elf_Internal_Shdr * symtab_hdr;
struct elf_link_hash_entry ** sym_hashes;
Elf_Internal_Rela * rel;
Elf_Internal_Rela * relend;
Elf_Internal_Shdr *symtab_hdr;
struct elf_link_hash_entry **sym_hashes;
Elf_Internal_Rela *rel;
Elf_Internal_Rela *relend;

if (info->relocatable)
return TRUE;

symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
sym_hashes = elf_sym_hashes (input_bfd);
relend = relocs + input_section->reloc_count;
symtab_hdr = &elf_tdata(input_bfd)->symtab_hdr;
sym_hashes = elf_sym_hashes(input_bfd);
relend = (relocs + input_section->reloc_count);

for (rel = relocs; rel < relend; rel ++)
{
reloc_howto_type * howto;
unsigned long r_symndx;
Elf_Internal_Sym * sym;
asection * sec;
struct elf_link_hash_entry * h;
bfd_vma relocation;
bfd_reloc_status_type r;
const char * name;
int r_type;
reloc_howto_type *howto;
unsigned long r_symndx;
Elf_Internal_Sym *sym;
asection *sec;
struct elf_link_hash_entry *h;
bfd_vma relocation;
bfd_reloc_status_type r;
const char *name;
int r_type;

/* This is a final link. */
r_type = ELF32_R_TYPE (rel->r_info);
r_symndx = ELF32_R_SYM (rel->r_info);
howto = elf_avr_howto_table + ELF32_R_TYPE (rel->r_info);
h = NULL;
sym = NULL;
sec = NULL;
r_type = ELF32_R_TYPE(rel->r_info);
r_symndx = ELF32_R_SYM(rel->r_info);
howto = (elf_avr_howto_table + r_type);
h = NULL;
sym = NULL;
sec = NULL;

if (r_symndx < symtab_hdr->sh_info)
{
sym = local_syms + r_symndx;
sec = local_sections [r_symndx];
relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);

name = bfd_elf_string_from_elf_section
(input_bfd, symtab_hdr->sh_link, sym->st_name);
name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
sym = (local_syms + r_symndx);
sec = local_sections[r_symndx];
relocation = _bfd_elf_rela_local_sym(output_bfd, sym, &sec, rel);

name =
bfd_elf_string_from_elf_section(input_bfd,
(unsigned int)symtab_hdr->sh_link,
(unsigned int)sym->st_name);
name = ((name == NULL) ? bfd_section_name(input_bfd, sec) : name);
}
else
{
bfd_boolean unresolved_reloc, warned;

RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
r_symndx, symtab_hdr, sym_hashes,
h, sec, relocation,
unresolved_reloc, warned);
RELOC_FOR_GLOBAL_SYMBOL(info, input_bfd, input_section, rel,
r_symndx, symtab_hdr, sym_hashes,
h, sec, relocation,
unresolved_reloc, warned);

name = h->root.root.string;
}

r = avr_final_link_relocate (howto, input_bfd, input_section,
contents, rel, relocation);
r = avr_final_link_relocate(howto, input_bfd, input_section,
contents, rel, relocation);

if (r != bfd_reloc_ok)
{
const char * msg = (const char *) NULL;
const char *msg = (const char *)NULL;

switch (r)
{
Expand Down
33 changes: 17 additions & 16 deletions src/bfd/elf32-cr16c.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,47 +720,48 @@ elf32_cr16c_relocate_section (bfd *output_bfd,
sec = NULL;
if (r_symndx < symtab_hdr->sh_info)
{
sym = local_syms + r_symndx;
sym = (local_syms + r_symndx);
sec = local_sections[r_symndx];
relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
relocation = _bfd_elf_rela_local_sym(output_bfd, sym, &sec, rel);
}
else
{
bfd_boolean unresolved_reloc, warned;

RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
r_symndx, symtab_hdr, sym_hashes,
h, sec, relocation,
unresolved_reloc, warned);
RELOC_FOR_GLOBAL_SYMBOL(info, input_bfd, input_section, rel,
r_symndx, symtab_hdr, sym_hashes,
h, sec, relocation,
unresolved_reloc, warned);
}

r = cr16c_elf_final_link_relocate (howto, input_bfd, output_bfd,
input_section,
contents, rel->r_offset,
relocation, rel->r_addend,
info, sec, h == NULL);
r = cr16c_elf_final_link_relocate(howto, input_bfd, output_bfd,
input_section, contents, rel->r_offset,
relocation, rel->r_addend, info, sec,
h == NULL);

if (r != bfd_reloc_ok)
{
const char *name;
const char *msg = (const char *) 0;
const char *msg = (const char *)0;

if (h != NULL)
name = h->root.root.string;
else
{
name = (bfd_elf_string_from_elf_section
(input_bfd, symtab_hdr->sh_link, sym->st_name));
name =
bfd_elf_string_from_elf_section(input_bfd,
(unsigned int)symtab_hdr->sh_link,
(unsigned int)sym->st_name);
if (name == NULL || *name == '\0')
name = bfd_section_name (input_bfd, sec);
name = bfd_section_name(input_bfd, sec);
}

switch (r)
{
case bfd_reloc_overflow:
if (!((*info->callbacks->reloc_overflow)
(info, (h ? &h->root : NULL), name, howto->name,
(bfd_vma) 0, input_bfd, input_section,
(bfd_vma)0UL, input_bfd, input_section,
rel->r_offset)))
return FALSE;
break;
Expand Down
44 changes: 24 additions & 20 deletions src/bfd/elf32-cris.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,12 @@ cris_elf_grok_prstatus(bfd *abfd, Elf_Internal_Note *note)

case 202: /* Linux/CRISv32 */
/* pr_cursig */
elf_tdata(abfd)->core_signal = bfd_get_16(abfd,
(note->descdata + 12));
elf_tdata(abfd)->core_signal = (int)bfd_get_16(abfd,
(note->descdata + 12));

/* pr_pid */
elf_tdata(abfd)->core_pid = bfd_get_32(abfd, note->descdata + 22);
elf_tdata(abfd)->core_pid = (int)bfd_get_32(abfd,
(note->descdata + 22));

/* pr_reg */
offset = 70;
Expand All @@ -533,10 +534,12 @@ cris_elf_grok_prstatus(bfd *abfd, Elf_Internal_Note *note)

case 214: /* Linux/CRIS */
/* pr_cursig */
elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
elf_tdata(abfd)->core_signal = (int)bfd_get_16(abfd,
(note->descdata + 12));

/* pr_pid */
elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 22);
elf_tdata(abfd)->core_pid = (int)bfd_get_32(abfd,
(note->descdata + 22));

/* pr_reg */
offset = 70;
Expand All @@ -546,24 +549,25 @@ cris_elf_grok_prstatus(bfd *abfd, Elf_Internal_Note *note)
}

/* Make a ".reg/999" section. */
return _bfd_elfcore_make_pseudosection (abfd, ".reg",
size, note->descpos + offset);
return _bfd_elfcore_make_pseudosection(abfd, ".reg", size,
(note->descpos + offset));
}

/* */
static bfd_boolean
cris_elf_grok_psinfo(bfd *abfd, Elf_Internal_Note *note)
{
if (bfd_get_mach (abfd) == bfd_mach_cris_v32)
if (bfd_get_mach(abfd) == bfd_mach_cris_v32)
switch (note->descsz)
{
default:
return FALSE;

case 124: /* Linux/CRISv32 elf_prpsinfo */
elf_tdata (abfd)->core_program
= _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
elf_tdata (abfd)->core_command
= _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
elf_tdata(abfd)->core_program =
_bfd_elfcore_strndup(abfd, (note->descdata + 28), 16);
elf_tdata(abfd)->core_command =
_bfd_elfcore_strndup(abfd, (note->descdata + 44), 80);
}
else
switch (note->descsz)
Expand All @@ -572,22 +576,22 @@ cris_elf_grok_psinfo(bfd *abfd, Elf_Internal_Note *note)
return FALSE;

case 124: /* Linux/CRIS elf_prpsinfo */
elf_tdata (abfd)->core_program
= _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
elf_tdata (abfd)->core_command
= _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
elf_tdata(abfd)->core_program =
_bfd_elfcore_strndup(abfd, (note->descdata + 28), 16);
elf_tdata(abfd)->core_command =
_bfd_elfcore_strndup(abfd, (note->descdata + 44), 80);
}

/* Note that for some reason, a spurious space is tacked
onto the end of the args in some (at least one anyway)
implementations, so strip it off if it exists. */

{
char *command = elf_tdata (abfd)->core_command;
int n = strlen (command);
char *command = elf_tdata(abfd)->core_command;
size_t n = strlen(command);

if (0 < n && command[n - 1] == ' ')
command[n - 1] = '\0';
if ((n > 0UL) && command[n - 1UL] == ' ')
command[n - 1UL] = '\0';
}

return TRUE;
Expand Down
Loading

0 comments on commit 770f324

Please sign in to comment.