Objcopy and alignment

Dave Murphy wintermute2k4@ntlworld.com
Tue May 18 14:40:00 GMT 2004


Is it possible to specify the alignment of binary data when using objcopy to
generate object  files from raw data? Failing that, can obcopy be told to
pad the length to, say, an even multiple of 4 bytes?

I'm currently using objcopy to link data in the executable for an embedded
target using makefile rules like this, to generate headers along with the
object file :-

define bin2o
	cp $(<) $(*).tmp
	$(OBJCOPY) -I binary -O elf32-littlearm -B arm \
	--rename-section .data=.rodata,readonly,data,contents \
	--redefine-sym _binary_$*_tmp_start=$*\
	--redefine-sym _binary_$*_tmp_end=$*_end\
	--redefine-sym _binary_$*_tmp_size=$*_size\
	$(*).tmp $(@)
	echo "extern const u8" $(*)"[];" > $(*).h
	echo "extern const u32" $(*)_size[]";" >> $(*).h
	rm $(*).tmp
endef

#---------------------------------------------------------------------------
------
%.o	:	%.pcx
#---------------------------------------------------------------------------
------
	@echo $(notdir $<)
	@$(bin2o)

occasionally the data is an odd length so any data following becomes
misaligned.


I've looked at the online docs -
http://sources.redhat.com/binutils/docs-2.15/binutils/objcopy.html and I can
see options for adjusting various addresses and a pad-to address option. How
can these options be used without knowing the addresses of the object being
modified? Surely they can't be known until link time?


Dave



More information about the Binutils mailing list