2007-07-09 Roland McGrath <roland@redhat.com>
* emultempl/elf32.em (gld${EMULATION_NAME}_add_option): Add --build-id. (gld${EMULATION_NAME}_handle_option): Handle --build-id. (gld${EMULATION_NAME}_list_options): List --build-id. (gld${EMULATION_NAME}_after_open): If --build-id was given, synthesize a ".note.gnu.build-id" section and cache it in elf_tdata. * ld.texinfo (Options): Describe --build-id. * NEWS: Mention --build-id.
This commit is contained in:
parent
ff59fc360e
commit
c0065db732
3
ld/NEWS
3
ld/NEWS
@ -2,6 +2,9 @@
|
||||
* Linker sources now released under version 3 of the GNU General Public
|
||||
License.
|
||||
|
||||
* ELF: New --build-id option to generate a unique per-binary identifier
|
||||
embedded in a note section.
|
||||
|
||||
* Added support for National Semicondutor CompactRISC (ie CR16) target.
|
||||
|
||||
* -l:foo now searches the library path for a filename called foo,
|
||||
|
@ -866,6 +866,45 @@ gld${EMULATION_NAME}_after_open (void)
|
||||
{
|
||||
struct bfd_link_needed_list *needed, *l;
|
||||
|
||||
if (link_info.emit_note_gnu_build_id)
|
||||
{
|
||||
bfd *abfd;
|
||||
asection *s;
|
||||
bfd_size_type size;
|
||||
|
||||
abfd = link_info.input_bfds;
|
||||
|
||||
size = _bfd_id_note_section_size (abfd, &link_info);
|
||||
if (size == 0)
|
||||
{
|
||||
einfo ("%P: warning: unrecognized --build-id style ignored.\n");
|
||||
free (link_info.emit_note_gnu_build_id);
|
||||
link_info.emit_note_gnu_build_id = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = bfd_make_section_with_flags (abfd, ".note.gnu.build-id",
|
||||
SEC_ALLOC | SEC_LOAD
|
||||
| SEC_IN_MEMORY | SEC_LINKER_CREATED
|
||||
| SEC_READONLY | SEC_DATA);
|
||||
if (s != NULL && bfd_set_section_alignment (abfd, s, 2))
|
||||
{
|
||||
struct elf_obj_tdata *t = elf_tdata (output_bfd);
|
||||
t->emit_note_gnu_build_id = link_info.emit_note_gnu_build_id;
|
||||
t->note_gnu_build_id_sec = s;
|
||||
elf_section_type (s) = SHT_NOTE;
|
||||
s->size = size;
|
||||
}
|
||||
else
|
||||
{
|
||||
einfo ("%P: warning: Cannot create .note.gnu.build-id section,"
|
||||
" --build-id ignored.\n");
|
||||
free (link_info.emit_note_gnu_build_id);
|
||||
link_info.emit_note_gnu_build_id = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (link_info.eh_frame_hdr
|
||||
&& ! link_info.traditional_format
|
||||
&& ! link_info.relocatable)
|
||||
@ -1760,6 +1799,7 @@ cat >>e${EMULATION_NAME}.c <<EOF
|
||||
#define OPTION_EH_FRAME_HDR (OPTION_GROUP + 1)
|
||||
#define OPTION_EXCLUDE_LIBS (OPTION_EH_FRAME_HDR + 1)
|
||||
#define OPTION_HASH_STYLE (OPTION_EXCLUDE_LIBS + 1)
|
||||
#define OPTION_BUILD_ID (OPTION_HASH_STYLE + 1)
|
||||
|
||||
static void
|
||||
gld${EMULATION_NAME}_add_options
|
||||
@ -1768,6 +1808,7 @@ gld${EMULATION_NAME}_add_options
|
||||
{
|
||||
static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
|
||||
static const struct option xtra_long[] = {
|
||||
{"build-id", optional_argument, NULL, OPTION_BUILD_ID},
|
||||
EOF
|
||||
|
||||
if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
|
||||
@ -1798,6 +1839,8 @@ cat >>e${EMULATION_NAME}.c <<EOF
|
||||
memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
|
||||
}
|
||||
|
||||
#define DEFAULT_BUILD_ID_STYLE "md5"
|
||||
|
||||
static bfd_boolean
|
||||
gld${EMULATION_NAME}_handle_option (int optc)
|
||||
{
|
||||
@ -1806,6 +1849,18 @@ gld${EMULATION_NAME}_handle_option (int optc)
|
||||
default:
|
||||
return FALSE;
|
||||
|
||||
case OPTION_BUILD_ID:
|
||||
if (link_info.emit_note_gnu_build_id != NULL)
|
||||
{
|
||||
free (link_info.emit_note_gnu_build_id);
|
||||
link_info.emit_note_gnu_build_id = NULL;
|
||||
}
|
||||
if (optarg == NULL)
|
||||
optarg = DEFAULT_BUILD_ID_STYLE;
|
||||
if (strcmp (optarg, "none"))
|
||||
link_info.emit_note_gnu_build_id = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
EOF
|
||||
|
||||
if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
|
||||
@ -1959,6 +2014,7 @@ cat >>e${EMULATION_NAME}.c <<EOF
|
||||
static void
|
||||
gld${EMULATION_NAME}_list_options (FILE * file)
|
||||
{
|
||||
fprintf (file, _(" --build-id[=STYLE]\tGenerate build ID note\n"));
|
||||
EOF
|
||||
|
||||
if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
|
||||
|
@ -1966,6 +1966,28 @@ has been used.
|
||||
The @option{--reduce-memory-overheads} switch may be also be used to
|
||||
enable other tradeoffs in future versions of the linker.
|
||||
|
||||
@kindex --build-id
|
||||
@kindex --build-id=@var{style}
|
||||
@item --build-id
|
||||
@itemx --build-id=@var{style}
|
||||
Request creation of @code{.note.gnu.build-id} ELF note section.
|
||||
The contents of the note are unique bits identifying this linked
|
||||
file. @var{style} can be @code{uuid} to use 128 random bits,
|
||||
@code{md5} to use a 128-bit @sc{MD5} hash on the normative parts
|
||||
of the output contents, or @code{0x@var{hexstring}} to use a
|
||||
chosen bit string specified as an even number of hexadecimal
|
||||
digits (@code{-} and @code{:} characters between digit pairs are
|
||||
ignored). If @var{style} is omitted, @code{md5} is used.
|
||||
|
||||
The @code{md5} style produces an identifier that is always the
|
||||
same in an identical output file, but will be unique among all
|
||||
nonidentical output files. It is not intended to be compared as
|
||||
a checksum for the file's contents. A linked file may be
|
||||
changed later by other tools, but the build ID bit string
|
||||
identifying the original linked file does not change.
|
||||
|
||||
Passing @code{none} for @var{style} disables the setting from any
|
||||
@code{--build-id} options earlier on the command line.
|
||||
@end table
|
||||
|
||||
@c man end
|
||||
|
Loading…
x
Reference in New Issue
Block a user