Commit Graph

8656 Commits

Author SHA1 Message Date
Kyle Evans
28e68bc000 O_SEARCH test: drop O_SEARCH|O_RDWR local diff
In FreeBSD's O_SEARCH implementation, O_SEARCH in conjunction with O_RDWR or
O_WRONLY is explicitly rejected. In this case, O_RDWR was not necessary
anyways as the file will get created with or without it.

This was submitted upstream as misc/54940 and committed in rev 1.8 of the
file.
2020-02-05 17:21:36 +00:00
Kyle Evans
56cc8b7595 O_SEARCH tests: plug trivial fd leak
Coverity correctly reports this as a resource leak. It's an admittedly minor
one, but plug it anyways.

This has been submitted upstream as misc/54939.

CID:		978288
2020-02-05 02:30:46 +00:00
Mark Johnston
85642eee46 readelf: Don't leak memory when dwarf_get_fde_info_for_all_regs() fails.
CID:		1292493
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2020-02-04 21:18:56 +00:00
Mark Johnston
37fa1df2d1 readelf: Fix the check for an error from realloc().
Use err() instead of errx() while here, since realloc() sets errno.

CID:		1401326
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2020-02-04 21:18:37 +00:00
Mark Johnston
dfa169049b readelf: Fix a double close of the input file.
The caller of dump_object() is responsible for opening the file, let it
be responsible for closing too.

CID:		1411588
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2020-02-04 21:18:16 +00:00
Mark Johnston
b7fc41b3ca size: Avoid returning a stack pointer from xlatetom().
The callers only check whether the returned pointer is non-NULL, so this
was harmless in practice, but change the return value to guard against
the issue.

CID:		1411597
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2020-02-04 21:17:59 +00:00
Mark Johnston
640ff6ed84 elfcopy: Avoid leaking dst's fd when we fail to copy a file.
We should really create the output file in the same directory as the
destination file so that rename() works.  This will be done in a future
change as part of some work to run in capability mode.

CID:		1262523
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2020-02-04 21:16:56 +00:00
Mark Johnston
f2530c80db elfcopy: Handle multiple data descriptors properly.
The code clearly meant to resize the buffer in the case where a section
was backed by multiple data descriptors.

In practice this shouldn't have been a problem since libelf would return
a single data descriptor for each section in a newly opened file.

CID:		1262522
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2020-02-04 21:16:41 +00:00
Mark Johnston
334f09a65b libelftc: Add a missing check for an error from vector_str_init().
While here consistently use the same spelling for such checks.

CID:		1376769
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2020-02-04 21:16:16 +00:00
Mark Johnston
a3c35da61b libelftc: Fix memory leaks in the C++ demanglers.
CID:		1262518, 1262519, 1262520, 1262529
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2020-02-04 21:15:52 +00:00
Mark Johnston
ab3b51df28 libdwarf: Fix a memory leak in _dwarf_frame_section_init().
If frame length validation failed we would leak memory.

CID:		1193366
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2020-02-04 21:15:29 +00:00
Mark Johnston
513e76aaf8 libdwarf: Make an out-pointer of _dwarf_abbrev_add() mandatory.
All callers pass a non-NULL pointer, and otherwise it was possible to
leak memory if the abbrev was not added to a CU.

CID:		1193365
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2020-02-04 21:15:11 +00:00
Mark Johnston
e5551befe8 libdwarf: Fix a possible memory leak in dwarf_add_AT_location_expr().
CID:		1193364
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2020-02-04 21:14:53 +00:00
Mark Johnston
75bd29add2 libdwarf: Remove unnecessary NULL checks.
All callers of _dwarf_add_expr() and _dwarf_expr_into_block() pass a
non-NULL expr pointer, and these functions assume that expr is non-NULL
anyway.

CID:		1193305, 1193306
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2020-02-04 21:14:34 +00:00
Cy Schubert
c998f2d39d Revert r357201: downgrade sqlite3 from sqlite3-3.31.0 (3310000) to
sqlite3-3.30.1 (3300100), as it causes svnlite segfaults on PowerPC,
resulting in corruption.

Reported by:	Mark Millard <marklmi at yahoo.com>
		Francis Little <oggy at farscape.co.uk>
2020-02-04 19:45:51 +00:00
Mark Johnston
35beedae40 addr2line: Avoid a name collision.
The RB_ macros define functions with a parameter named head, and gcc
warns about this.

MFC with:	r357450
2020-02-03 19:08:35 +00:00
Mark Johnston
af84329100 addr2line: Cache CU DIEs upon a successful address lookup.
Previously, addr2line would sequentially search all CUs for each input
address.  For some uses, notably syzkaller's code coverage map generator,
this was extremely slow.  Add a CU cache into which entries are added
following a successful lookup, and search the cache before falling back
to a scan.  When translating a large number of addresses this yields
slightly better performance than GNU addr2line.

Garbage-collect an unused hash table which appears to have been intended
for the same purpose.  A hash table doesn't seem particularly suitable
since each CU spans a range of addresses.

Submitted by:	Tiger Gao <tig@freebsdfoundation.org>
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D23418
2020-02-03 16:41:40 +00:00
Kyle Evans
6a5abb1ee5 Provide O_SEARCH
O_SEARCH is defined by POSIX [0] to open a directory for searching, skipping
permissions checks on the directory itself after the initial open(). This is
close to the semantics we've historically applied for O_EXEC on a directory,
which is UB according to POSIX. Conveniently, O_SEARCH on a file is also
explicitly undefined behavior according to POSIX, so O_EXEC would be a fine
choice. The spec goes on to state that O_SEARCH and O_EXEC need not be
distinct values, but they're not defined to be the same value.

This was pointed out as an incompatibility with other systems that had made
its way into libarchive, which had assumed that O_EXEC was an alias for
O_SEARCH.

This defines compatibility O_SEARCH/FSEARCH (equivalent to O_EXEC and FEXEC
respectively) and expands our UB for O_EXEC on a directory. O_EXEC on a
directory is checked in vn_open_vnode already, so for completeness we add a
NOEXECCHECK when O_SEARCH has been specified on the top-level fd and do not
re-check that when descending in namei.

[0] https://pubs.opengroup.org/onlinepubs/9699919799/

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D23247
2020-02-02 16:34:57 +00:00
Ed Maste
43e8403953 retire BSD_CRTBEGIN option
BSD crt is currently used on all architectures (other than sparc64).
Remove the option and use BSD crt everywhere as part of the GCC 4.2.1
retirement plan.

https://lists.freebsd.org/pipermail/freebsd-arch/2020-January/019823.html

PR:		239851
Reviewed by:	andrew, brooks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D23122
2020-01-31 18:04:04 +00:00
Conrad Meyer
53345534c8 contrib/apr: Rip out bogus [CS]PRNG implementation
This construction used some relatively slow design involving SHA2; even if
it were fed real entropy (unclear; external to the design), it did not
handle fork in a safe way, and it was difficult to audit for correctness.
So just rip it out and use the very simple and known-correct arc4random(3)
interface in its place.
2020-01-30 18:12:41 +00:00
Conrad Meyer
e3907d2395 contrib/apr: Remove scope leak UB
In apr_vformatter, the variable buf was declared inside a limited scope
region, but a pointer to it is leaked outside of that region and used
later.  This is undefined behavior.  Fix by moving the buf variable to
function scope.

Reported by:	Coverity
CID:		1192541
2020-01-30 17:50:51 +00:00
Dimitry Andric
8841e3fb92 Merge r357224 from the clang1000-import branch:
Fix the following -Werror warning from clang 10.0.0 in binutils:

contrib/binutils/bfd/peicode.h:1356:3: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation]
                if (efi)
                ^
contrib/binutils/bfd/peicode.h:1353:8: note: previous statement is here
              if (pe_arch (bfd_target_efi_arch (*target_ptr)) != arch)
              ^
contrib/binutils/bfd/peicode.h:1370:3: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation]
                if (!efi)
                ^
contrib/binutils/bfd/peicode.h:1367:8: note: previous statement is here
              if (pe_arch (bfd_target_pei_arch (*target_ptr)) != arch)
              ^

MFC after:	3 days
2020-01-28 20:11:27 +00:00
Dimitry Andric
62b61cee41 Fix the following -Werror warning from clang 10.0.0 in binutils:
contrib/binutils/bfd/peicode.h:1356:3: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation]
                if (efi)
                ^
contrib/binutils/bfd/peicode.h:1353:8: note: previous statement is here
              if (pe_arch (bfd_target_efi_arch (*target_ptr)) != arch)
              ^
contrib/binutils/bfd/peicode.h:1370:3: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation]
                if (!efi)
                ^
contrib/binutils/bfd/peicode.h:1367:8: note: previous statement is here
              if (pe_arch (bfd_target_pei_arch (*target_ptr)) != arch)
              ^

MFC after:	3 days
2020-01-28 20:09:23 +00:00
Dimitry Andric
4f73ee074c Prefer upstream RISC-V additions in libunwind instead of ours, as these
arrived via roundabout way upstream, and got updated in the mean time.
2020-01-28 18:04:17 +00:00
Cy Schubert
882f88ff77 MFV r357163:
Update sqlite3-3.30.1 (3300100) --> sqlite3-3.31.0 (3310000)

MFC after:	1 month
2020-01-28 13:13:41 +00:00
Kyle Evans
45c88a3cbb netbsd-tests: libc: use correct modes in O_SEARCH tests
The current code clearly intended for these to be octal based on the values
used, but the octal prefix was forgotten. Add it now for correctness, but
note that we don't currently execute these tests.

This has been submitted upstream as misc/54902, so I've omitted the standard
FreeBSD markers that we tend to put into netbsd-tests for upstream-candidate
identification.

Reviewed by:	ngie
MFC after:	3 days
2020-01-28 03:47:29 +00:00
Dimitry Andric
773bec0868 Merge ^/head r357119 through r357178. 2020-01-27 20:47:18 +00:00
Dimitry Andric
f46f1d2836 Update build glue for lldb (MK_LLDB=yes). Also update lldb's generated
Config.h, disable a few more parts in the code we don't use, and add a
pre-generated man page.
2020-01-27 16:52:44 +00:00
Dimitry Andric
56e766af41 Update build glue for lld (MK_LLD=yes). Also update invocation of
elf::link() in lld.cpp.
2020-01-26 21:55:17 +00:00
Phil Shafer
5c5819b2b6 Import libxo-1.4.0:
- Two changes to encoder options:
        encoder options may use plus or colon, but only one
        encoder names can be specified as "@name"
        This results in the syntax:

        df --libxo @csv:no-header:leafs=name.available-blocks /

    - If xo_set_program is called before xo_parse_args, honor the requested value
    - add xo_errorn* function; repair newline-adding-on-xo_error bug
    - test programs now use fixed name, since linux libtool prefixs "lt-"
    - Fix "horse butt" comment in source code
    - update test cases

PR:		242686
2020-01-25 21:16:45 +00:00
Dimitry Andric
e5258cefd2 Further reduce diffs between upstream and our version. 2020-01-25 14:43:22 +00:00
Dimitry Andric
19a3930692 Update FREEBSD-Xlist. 2020-01-25 14:39:59 +00:00
Dimitry Andric
55e4f9d541 Merge ^/vendor/lvm-project/release-10.x up to its last change (upstream
commit llvmorg-10-init-17538-gd11abddb32f).
2020-01-24 22:15:36 +00:00
Dimitry Andric
6528635081 Merge ^/vendor/lvm-project/release-10.x up to its last change (upstream
commit c4a134a51).
2020-01-24 22:04:02 +00:00
Dimitry Andric
480093f444 Merge ^/vendor/lvm-project/master up to its last change (upstream commit
e26a78e70), and resolve conflicts.
2020-01-24 22:00:03 +00:00
Dimitry Andric
489b1cf2ec Merge ^/vendor/llvm-openmp/dist up to its last change, and resolve conflicts. 2020-01-23 21:42:26 +00:00
Dimitry Andric
9dba64be95 Merge ^/vendor/lldb/dist up to its last change, and resolve conflicts. 2020-01-23 21:36:25 +00:00
Dimitry Andric
85868e8a1d Merge ^/vendor/lld/dist up to its last change, and resolve conflicts. 2020-01-23 21:35:51 +00:00
Dimitry Andric
c2c6a17905 Merge ^/vendor/llvm-libunwind/dist up to its last change, and resolve conflicts. 2020-01-23 07:10:23 +00:00
Dimitry Andric
e40139ff33 Merge ^/vendor/libc++/dist up to its last change, and resolve conflicts. 2020-01-23 07:06:18 +00:00
Dimitry Andric
68d75eff68 Merge ^/vendor/compiler-rt/dist up to its last change, and resolve conflicts. 2020-01-22 22:01:43 +00:00
Dimitry Andric
a7dea1671b Merge ^/vendor/clang/dist up to its last change, and resolve conflicts. 2020-01-22 21:31:48 +00:00
Dimitry Andric
5c713029ff Reduce diff between stock DWARFContext.cpp and ours. 2020-01-22 21:22:34 +00:00
Dimitry Andric
8bcb099186 Merge ^/vendor/llvm/dist up to its last change, and resolve conflicts. 2020-01-22 20:31:01 +00:00
Dimitry Andric
b14637d118 Merge ^/head r356920 through r356930. 2020-01-20 20:27:51 +00:00
Dimitry Andric
f8e1cfad89 Merge commit bc4bc5aa0 from llvm git (by Justin Hibbits):
Add 8548 CPU definition and attributes

  8548 CPU is GCC's name for the e500v2, so accept this in clang.  The
  e500v2 doesn't support lwsync, so define __NO_LWSYNC__ for this as
  well, as GCC does.

  Differential Revision:  https://reviews.llvm.org/D67787

Merge commit ff0311c4b from llvm git (by Justin Hibbits):

  [PowerPC]: Add powerpcspe target triple subarch component

  Summary:
  This allows the use of '-target powerpcspe-unknown-linux-gnu' or
  'powerpcspe-unknown-freebsd' to be used, instead of '-target
  powerpc-unknown-linux-gnu -mspe'.

  Reviewed By: dim
  Differential Revision: https://reviews.llvm.org/D72014

Merge commit ba91dffaf from llvm git (by Fangrui Song):

  [Driver][PowerPC] Move powerpcspe logic from cc1 to Driver

  Follow-up of D72014. It is more appropriate to use a target feature
  instead of a SubTypeArch to express the difference.

  Reviewed By: #powerpc, jhibbits

  Differential Revision: https://reviews.llvm.org/D72433

commit 36eedfcb3 from llvm git (by Justin Hibbits):

  [PowerPC] Fix powerpcspe subtarget enablement in llvm backend

  Summary:

  As currently written, -target powerpcspe will enable SPE regardless
  of disabling the feature later on in the command line.  Instead,
  change this to just set a default CPU to 'e500' instead of a generic
  CPU.

  As part of this, add FeatureSPE to the e500 definition.

  Reviewed By: MaskRay
  Differential Revision: https://reviews.llvm.org/D72673

These are needed to unbreak the build for powerpcspe.

Requested by:	jhibbits
MFC after:	1 week
2020-01-20 20:10:28 +00:00
Dimitry Andric
2dd94b045e Merge ^/vendor/llvm-project/master until just before r356843. 2020-01-20 18:21:55 +00:00
Alex Richardson
80500f4ed6 Merge commit 894f742acb from llvm git (by me):
[MIPS][ELF] Use PC-relative relocations in .eh_frame when possible

  When compiling position-independent executables, we now use
  DW_EH_PE_pcrel | DW_EH_PE_sdata4. However, the MIPS ABI does not define a
  64-bit PC-relative ELF relocation so we cannot use sdata8 for the large
  code model case. When using the large code model, we fall back to the
  previous behaviour of generating absolute relocations.

  With this change clang-generated .o files can be linked by LLD without
  having to pass -Wl,-z,notext (which creates text relocations).
  This is simpler than the approach used by ld.bfd, which rewrites the
  .eh_frame section to convert absolute relocations into relative references.

  I saw in D13104 that apparently ld.bfd did not accept pc-relative relocations
  for MIPS ouput at some point. However, I also checked that recent ld.bfd
  can process the clang-generated .o files so this no longer seems true.

  Reviewed By: atanasyan
  Differential Revision: https://reviews.llvm.org/D72228

Merge commit 8e8ccf47 from llvm git (by me)

  [MIPS] Don't emit R_(MICRO)MIPS_JALR relocations against data symbols

  The R_(MICRO)MIPS_JALR optimization only works when used against functions.
  Using the relocation against a data symbol (e.g. function pointer) will
  cause some linkers that don't ignore the hint in this case (e.g. LLD prior
  to commit 5bab291) to generate a relative branch to the data symbol
  which crashes at run time. Before this patch, LLVM was erroneously emitting
  these relocations against local-dynamic TLS function pointers and global
  function pointers with internal visibility.

  Reviewers: atanasyan, jrtc27, vstefanovic
  Reviewed By: atanasyan
  Differential Revision: https://reviews.llvm.org/D72571

These two changes should allow using lld for MIPS64 (and maybe also MIPS32)
by default.
The second commit is not strictly necessary for clang+lld since LLD9 will
not perform the R_MIPS_JALR optimization (it was only added for 10) but it
is probably required in order to use recent ld.bfd.

Reviewed By:	dim, emaste
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D23203
2020-01-16 14:14:50 +00:00
Dimitry Andric
f10421e96d Merge commit f46ba4f07 from llvm git (by Simon Atanasyan):
[mips] Use less registers to load address of TargetExternalSymbol

  There is no pattern matched `add hi, (MipsLo texternalsym)`. As a
  result, loading an address of 32-bit symbol requires two registers
  and one more additional instruction:
  ```
  addiu $1, $zero, %lo(foo)
  lui   $2, %hi(foo)
  addu  $25, $2, $1
  ```

  This patch adds the missed pattern and enables generation more
  effective set of instructions:
  ```
  lui   $1, %hi(foo)
  addiu $25, $1, %lo(foo)
  ```

  Differential Revision: https://reviews.llvm.org/D66771

  llvm-svn: 370196

Merge commit 59bb3609f from llvm git (by Simon Atanasyan):

  [mips] Fix 64-bit address loading in case of applying 32-bit mask to
  the result

  If result of 64-bit address loading combines with 32-bit mask, LLVM
  tries to optimize the code and remove "redundant" loading of upper
  32-bits of the address. It leads to incorrect code on MIPS64 targets.

  MIPS backend creates the following chain of commands to load 64-bit
  address in the `MipsTargetLowering::getAddrNonPICSym64` method:
  ```
  (add (shl (add (shl (add %highest(sym), %higher(sym)),
		      16),
		 %hi(sym)),
	    16),
       %lo(%sym))
  ```

  If the mask presents, LLVM decides to optimize the chain of commands.
  It really does not make sense to load upper 32-bits because the
  0x0fffffff mask anyway clears them. After removing redundant commands
  we get this chain:
  ```
  (add (shl (%hi(sym), 16), %lo(%sym))
  ```

  There is no patterns matched `(MipsHi (i64 symbol))`. Due a bug in
  `SYM_32` predicate definition, backend incorrectly selects a pattern
  for a 32-bit symbols and uses the `lui` instruction for loading
  `%hi(sym)`.

  As a result we get incorrect set of instructions with unnecessary
  16-bit left shifting:
  ```
  lui     at,0x0
      R_MIPS_HI16     foo
  dsll    at,at,0x10
  daddiu  at,at,0
      R_MIPS_LO16     foo
  ```

  This patch resolves two problems:
  - Fix `SYM_32/SYM_64` predicates to prevent selection of patterns
    dedicated to 32-bit symbols in case of using N64 ABI.
  - Add missed patterns for 64-bit symbols for `%hi/%lo`.

  Fix PR42736.

  Differential Revision: https://reviews.llvm.org/D66228

  llvm-svn: 370268

These two commits fix a miscompilation of the kernel for mips64, and
should allow clang to be used as the default compiler for mips64.

Requested by:	arichards
MFC after:	3 days
2020-01-13 20:31:10 +00:00
Cy Schubert
6692aa840c Unbound's config.h is manually maintained, using a ./configure produced
config.h as a guide. In practice contributed software maintains a copy
of config.h within its build directory tree containing its Makefile.
usr.sbin/unbound is the home for its config.h.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D22983
2020-01-13 06:55:31 +00:00