Bug 12739 - [patch] bfd_get warns under -Wcast-qual
Summary: [patch] bfd_get warns under -Wcast-qual
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: unspecified
: P2 minor
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-06 23:24 UTC by Anders Kaseorg
Modified: 2011-05-29 04:53 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anders Kaseorg 2011-05-06 23:24:00 UTC
This fixes bfd_get_8 (hence also bfd_get, which uses it) to accept const void * without emitting a warning under gcc -Wcast-qual:
warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]

--- a/bfd/libbfd.c
+++ b/bfd/libbfd.c
@@ -431,9 +431,9 @@ DESCRIPTION
 .#define bfd_put_signed_8 \
 .  bfd_put_8
 .#define bfd_get_8(abfd, ptr) \
-.  (*(unsigned char *) (ptr) & 0xff)
+.  (*(const unsigned char *) (ptr) & 0xff)
 .#define bfd_get_signed_8(abfd, ptr) \
-.  (((*(unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80)
+.  (((*(const unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80)
 .
 .#define bfd_put_16(abfd, val, ptr) \
 .  BFD_SEND (abfd, bfd_putx16, ((val),(ptr)))
Comment 1 Sourceware Commits 2011-05-07 13:48:54 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2011-05-07 13:48:51

Modified files:
	bfd            : ChangeLog libbfd.c bfd-in2.h 

Log message:
	PR 12739
	* libbfd.c (bfd_get_8, bfd_get_signed_8): Use const cast.
	* bfd-in2.h: Regenerate.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5331&r2=1.5332
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/libbfd.c.diff?cvsroot=src&r1=1.56&r2=1.57
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/bfd-in2.h.diff?cvsroot=src&r1=1.534&r2=1.535
Comment 2 Alan Modra 2011-05-07 13:50:44 UTC
Applied
Comment 3 Sourceware Commits 2011-05-29 04:53:00 UTC
CVSROOT:	/cvs/src
Module name:	src
Branch: 	binutils-2_21-branch
Changes by:	amodra@sourceware.org	2011-05-29 04:51:53

Modified files:
	bfd            : ChangeLog aoutx.h archive.c bfd-in2.h bfdio.c 
	                 coff-aux.c coffcode.h coffgen.c cofflink.c 
	                 config.in configure configure.in dwarf2.c 
	                 elf-bfd.h elf-m10300.c elf.c elf32-ppc.c 
	                 elf32-rx.c elf64-ppc.c elflink.c elfxx-ia64.c 
	                 libbfd.c linker.c peXXigen.c vms-alpha.c 
	bfd/hosts      : x86-64linux.h 
	binutils       : ChangeLog nm.c objcopy.c 
	binutils/doc   : binutils.texi 
	binutils/testsuite: ChangeLog 
	binutils/testsuite/binutils-all: nm.exp 
	binutils/testsuite/lib: utils-lib.exp 
	gas            : ChangeLog dwarf2dbg.c input-scrub.c messages.c 
	                 read.c 
	gas/config     : obj-elf.h tc-arc.c tc-d10v.h tc-d30v.h 
	                 tc-m32r.h 
	gas/testsuite  : ChangeLog 
	gas/testsuite/gas/i386: inval-equ-2.l 
	gas/testsuite/gas/symver: symver2.l 
	include        : ChangeLog ansidecl.h bfdlink.h 
	ld             : ChangeLog ldexp.c ldlang.c ldlex.l ldmain.c 
	                 plugin.c 
	ld/emultempl   : elf32.em pe.em pep.em 
	ld/scripttempl : pe.sc pep.sc 
	ld/testsuite   : ChangeLog 
	ld/testsuite/ld-cris: tls-e-tpoffcomm1.d 
	ld/testsuite/ld-plugin: plugin-7.d plugin-8.d 

Log message:
	PR 12365
	PR 12613
	PR 12632
	PR 12739
	PR 12753
	PR 12760
	PR 12763
	Apply fix from mainline along with assorted other small fixes.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.5180.2.34&r2=1.5180.2.35
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/aoutx.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.84.2.1&r2=1.84.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/archive.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.69.2.3&r2=1.69.2.4
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/bfd-in2.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.522.2.2&r2=1.522.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/bfdio.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.27&r2=1.27.4.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/coff-aux.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.10.10.1&r2=1.10.10.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/coffcode.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.171&r2=1.171.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/coffgen.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.78&r2=1.78.4.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/cofflink.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.74.2.1&r2=1.74.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/config.in.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.48&r2=1.48.4.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/configure.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.339.2.4&r2=1.339.2.5
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/configure.in.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.287.2.4&r2=1.287.2.5
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/dwarf2.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.138&r2=1.138.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf-bfd.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.313.2.2&r2=1.313.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf-m10300.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.106&r2=1.106.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.524.2.2&r2=1.524.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf32-ppc.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.290.2.3&r2=1.290.2.4
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf32-rx.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.5.2.1&r2=1.5.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf64-ppc.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.339.2.10&r2=1.339.2.11
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elflink.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.388.2.2&r2=1.388.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elfxx-ia64.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.228.2.1&r2=1.228.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/libbfd.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.53.2.1&r2=1.53.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/linker.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.77.2.2&r2=1.77.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/peXXigen.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.67&r2=1.67.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/vms-alpha.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.37.2.1&r2=1.37.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/hosts/x86-64linux.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.2&r2=1.2.4.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/binutils/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.1708.2.9&r2=1.1708.2.10
http://sourceware.org/cgi-bin/cvsweb.cgi/src/binutils/nm.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.65&r2=1.65.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/binutils/objcopy.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.147.2.1&r2=1.147.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/binutils/doc/binutils.texi.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.173.2.1&r2=1.173.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/binutils/testsuite/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.216.2.2&r2=1.216.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/binutils/testsuite/binutils-all/nm.exp.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.5&r2=1.5.4.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/binutils/testsuite/lib/utils-lib.exp.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.20.2.1&r2=1.20.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.4320.2.29&r2=1.4320.2.30
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/dwarf2dbg.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.107&r2=1.107.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/input-scrub.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.23&r2=1.23.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/messages.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.23&r2=1.23.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/read.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.167.2.2&r2=1.167.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/obj-elf.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.38&r2=1.38.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-arc.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.47&r2=1.47.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-d10v.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.20&r2=1.20.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-d30v.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.15&r2=1.15.4.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-m32r.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.23&r2=1.23.4.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.1802.2.11&r2=1.1802.2.12
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/i386/inval-equ-2.l.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.1&r2=1.1.12.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/symver/symver2.l.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.1&r2=1.1.38.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.510.2.2&r2=1.510.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/ansidecl.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.28&r2=1.28.6.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/include/bfdlink.h.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.82.2.1&r2=1.82.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.2222.2.23&r2=1.2222.2.24
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldexp.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.87.2.2&r2=1.87.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldlang.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.347.2.5&r2=1.347.2.6
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldlex.l.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.47.2.2&r2=1.47.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ldmain.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.145.2.3&r2=1.145.2.4
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/plugin.c.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.7.2.5&r2=1.7.2.6
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/emultempl/elf32.em.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.214.2.1&r2=1.214.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/emultempl/pe.em.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.162.2.2&r2=1.162.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/emultempl/pep.em.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.38.2.1&r2=1.38.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/scripttempl/pe.sc.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.24&r2=1.24.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/scripttempl/pep.sc.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.13&r2=1.13.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.1322.2.12&r2=1.1322.2.13
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-cris/tls-e-tpoffcomm1.d.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.1&r2=1.1.6.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-plugin/plugin-7.d.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.1.2.1&r2=1.1.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-plugin/plugin-8.d.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.1.2.1&r2=1.1.2.2