binutils-gdb/libiberty/sort.c
Nick Clifton 2a8ae7146c Update the libiberty sources with the latest patches found in the master sources.
2017-01-02  Richard Biener  <rguenther@suse.de>

	PR lto/83452
	* simple-object-elf.c (simple_object_elf_copy_lto_debug_section):
	Do not use UNDEF locals for removed symbols but instead just
	define them in the first prevailing section and with no name.
	Use the same gnu_lto_v1 name for all removed globals we promote to
	WEAK UNDEFs so hpux can use a stub to provide this symbol.  Clear
	sh_info and sh_link in removed sections.

2017-10-30  Richard Biener  <rguenther@suse.de>

	PR lto/82757
	* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
	Strip two leading _s from the __gnu_lto_* symbols.

2017-10-24  Alan Modra  <amodra@gmail.com>

	PR lto/82687
	PR lto/82575
	* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
	Only make __gnu_lto symbols hidden.

2017-10-20  Alan Modra  <amodra@gmail.com>

	PR lto/82575
	* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
	Make discarded non-local symbols weak and hidden.

2017-10-18  Jakub Jelinek  <jakub@redhat.com>

	PR lto/82598
	* simple-object.c (handle_lto_debug_sections): Copy over also
	.note.GNU-stack section with unchanged name.
	* simple-object-elf.c (SHF_EXECINSTR): Define.
	(simple_object_elf_copy_lto_debug_section): Drop SHF_EXECINSTR bit
	on .note.GNU-stack section.

2017-09-25  Nathan Sidwell  <nathan@acm.org>

	PR demangler/82195
	* cp-demangle.c (d_encoding): Strip return type when name is a
	LOCAL_NAME.
	(d_local_name): Strip return type of enclosing TYPED_NAME.
	* testsuite/demangle-expected: Add and adjust tests.

2017-09-21  Nathan Sidwell  <nathan@acm.org>

	PR demangler/82195
	* cp-demangle.c (d_name): Revert addition of 'toplevel' parm.
	(has_return_type): Recurse for DEMANGLE_COMPONENT_LOCAL_NAME.
	(d_encoding): Revert d_name change.  Use is_fnqual_component_type
	to strip modifiers that do not belong.
	(d_special_name, d_class_enum_type): Revert d_name call change.
	(d_expresion_1): Commonize DEMANGLE_COMPONENT_UNARY building.
	(d_local_name): Revert parsing of a function type.
	(d_print_comp_inner): An inner LOCAL_NAME might contain a
	TEMPLATE.
	* testsuite/demangle-expected: Add & adjust tests
2018-01-10 13:57:48 +00:00

187 lines
4.8 KiB
C

/* Sorting algorithms.
Copyright (C) 2000-2018 Free Software Foundation, Inc.
Contributed by Mark Mitchell <mark@codesourcery.com>.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 51 Franklin Street - Fifth Floor,
Boston, MA 02110-1301, USA. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "libiberty.h"
#include "sort.h"
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifndef UCHAR_MAX
#define UCHAR_MAX ((unsigned char)(-1))
#endif
/* POINTERS and WORK are both arrays of N pointers. When this
function returns POINTERS will be sorted in ascending order. */
void sort_pointers (size_t n, void **pointers, void **work)
{
/* The type of a single digit. This can be any unsigned integral
type. When changing this, DIGIT_MAX should be changed as
well. */
typedef unsigned char digit_t;
/* The maximum value a single digit can have. */
#define DIGIT_MAX (UCHAR_MAX + 1)
/* The Ith entry is the number of elements in *POINTERSP that have I
in the digit on which we are currently sorting. */
unsigned int count[DIGIT_MAX];
/* Nonzero if we are running on a big-endian machine. */
int big_endian_p;
size_t i;
size_t j;
/* The algorithm used here is radix sort which takes time linear in
the number of elements in the array. */
/* The algorithm here depends on being able to swap the two arrays
an even number of times. */
if ((sizeof (void *) / sizeof (digit_t)) % 2 != 0)
abort ();
/* Figure out the endianness of the machine. */
for (i = 0, j = 0; i < sizeof (size_t); ++i)
{
j *= (UCHAR_MAX + 1);
j += i;
}
big_endian_p = (((char *)&j)[0] == 0);
/* Move through the pointer values from least significant to most
significant digits. */
for (i = 0; i < sizeof (void *) / sizeof (digit_t); ++i)
{
digit_t *digit;
digit_t *bias;
digit_t *top;
unsigned int *countp;
void **pointerp;
/* The offset from the start of the pointer will depend on the
endianness of the machine. */
if (big_endian_p)
j = sizeof (void *) / sizeof (digit_t) - i;
else
j = i;
/* Now, perform a stable sort on this digit. We use counting
sort. */
memset (count, 0, DIGIT_MAX * sizeof (unsigned int));
/* Compute the address of the appropriate digit in the first and
one-past-the-end elements of the array. On a little-endian
machine, the least-significant digit is closest to the front. */
bias = ((digit_t *) pointers) + j;
top = ((digit_t *) (pointers + n)) + j;
/* Count how many there are of each value. At the end of this
loop, COUNT[K] will contain the number of pointers whose Ith
digit is K. */
for (digit = bias;
digit < top;
digit += sizeof (void *) / sizeof (digit_t))
++count[*digit];
/* Now, make COUNT[K] contain the number of pointers whose Ith
digit is less than or equal to K. */
for (countp = count + 1; countp < count + DIGIT_MAX; ++countp)
*countp += countp[-1];
/* Now, drop the pointers into their correct locations. */
for (pointerp = pointers + n - 1; pointerp >= pointers; --pointerp)
work[--count[((digit_t *) pointerp)[j]]] = *pointerp;
/* Swap WORK and POINTERS so that POINTERS contains the sorted
array. */
pointerp = pointers;
pointers = work;
work = pointerp;
}
}
/* Everything below here is a unit test for the routines in this
file. */
#ifdef UNIT_TEST
#include <stdio.h>
void *xmalloc (size_t n)
{
return malloc (n);
}
int main (int argc, char **argv)
{
int k;
int result;
size_t i;
void **pointers;
void **work;
if (argc > 1)
k = atoi (argv[1]);
else
k = 10;
pointers = XNEWVEC (void*, k);
work = XNEWVEC (void*, k);
for (i = 0; i < k; ++i)
{
pointers[i] = (void *) random ();
printf ("%x\n", pointers[i]);
}
sort_pointers (k, pointers, work);
printf ("\nSorted\n\n");
result = 0;
for (i = 0; i < k; ++i)
{
printf ("%x\n", pointers[i]);
if (i > 0 && (char*) pointers[i] < (char*) pointers[i - 1])
result = 1;
}
free (pointers);
free (work);
return result;
}
#endif