summaryrefslogtreecommitdiffstats
path: root/sys/kern/link_elf_obj.c
Commit message (Collapse)AuthorAgeFilesLines
* kern: for pointers replace 0 with NULL.pfg2016-04-151-2/+2
| | | | | | These are mostly cosmetical, no functional change. Found with devel/coccinelle.
* Use the ABI-prescribed name for SHT_X86_64_UNWIND in the loader andkib2016-04-081-8/+8
| | | | | | kernel linker, after the r297686. Sponsored by: The FreeBSD Foundation
* Convert all panics from the link_elf_obj kernel linker for objectkib2016-03-071-41/+92
| | | | | | | | | | files format into printfs and errors to caller. Some leaks of resources are there, but the same leaks are present in other error pathes. With the change, the kernel at least boots even when module with unexpected or corrupted ELF structure is preloaded. Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
* In the link_elf_obj.c, handle sections of type SHT_AMD64_UNWIND samekib2016-03-061-1/+28
| | | | | | | | | | | | as SHT_PROGBITS. This is needed after the clang 3.8 import, which generates that type for .eh_frame section, which had SHT_PROGBITS type before. Reported by: Nikolai Lifanov <lifanov@mail.lifanov.com> PR: 207729 Tested by: dim (previous version) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
* Remove useless checks for NULL before calling free(9), in the kernelkib2016-02-101-38/+19
| | | | | | | | elf linkers. Found by: Related PVS-Studio diagnostic Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Add support for weak symbols to the kernel linkers. It means thatkib2015-09-201-20/+31
| | | | | | | | | | | | | | | | | | | | | | linkers no longer raise an error when undefined weak symbols are found, but relocate as if the symbol value was 0. Note that we do not repeat the mistake of userspace dynamic linker of making the symbol lookup prefer non-weak symbol definition over the weak one, if both are available. In fact, kernel linker uses the first definition found, and ignores duplicates. Signature of the elf_lookup() and elf_obj_lookup() functions changed to split result/error code and the symbol address returned. Otherwise, it is impossible to return zero address as the symbol value, to MD relocation code. This explains the mechanical changes in elf_machdep.c sources. The powerpc64 R_PPC_JMP_SLOT handler did not checked error from the lookup() call, the patch leaves the code as is (untested). Reported by: glebius Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Move zlib.c from net to libkern.rodrigc2015-04-221-1/+1
| | | | | | | | | | | | It is not network-specific code and would be better as part of libkern instead. Move zlib.h and zutil.h from net/ to sys/ Update includes to use sys/zlib.h and sys/zutil.h instead of net/ Submitted by: Steve Kiernan stevek@juniper.net Obtained from: Juniper Networks, Inc. GitHub Pull Request: https://github.com/freebsd/freebsd/pull/28 Relnotes: yes
* Speed up symbol lookup for the amd64 kernel modules.kib2015-04-021-2/+40
| | | | | | | | | | | | | | | | | | | | Amd64 uses relocatable object files as the modules format. It is good WRT not having unneeded overhead for PIC code, in particular, due to absence of useless GOT and PLT. But the cost is that the module linking process cannot use hash to speed up the symbol lookup, and that each reference to the symbol requiring a relocation, instead of single-place relocation in GOT. Cache the successfull symbol lookup results in the module symbol table, using the newly allocated SHN_FBSD_CACHED value from SHN_LOOS-HIOS range as an indicator. The SHN_FBSD_CACHED together with the non-existent definition of the found symbol are reverted after successfull relocations, which is done under kld_sx lock, so it should not be visible to other consumers of the symbol table. Submitted by: Conrad Meyer Differential Revision: https://reviews.freebsd.org/D1718 MFC after: 3 weeks
* Fully support constructors for the purpose of code coverage analysis.marcel2014-10-201-2/+31
| | | | | | | | | | | | | | | | | This involves: 1. Have the loader pass the start and size of the .ctors section to the kernel in 2 new metadata elements. 2. Have the linker backends look for and record the start and size of the .ctors section in dynamically loaded modules. 3. Have the linker backends call the constructors as part of the final work of initializing preloaded or dynamically loaded modules. Note that LLVM appends the priority of the constructors to the name of the .ctors section. Not so when compiling with GCC. The code currently works for GCC and not for LLVM. Submitted by: Dmitry Mikulin <dmitrym@juniper.net> Obtained from: Juniper Networks, Inc.
* Add a mmap flag (MAP_32BIT) on 64-bit platforms to request that a mapping usejhb2013-09-091-1/+2
| | | | | | | | | | | | | an address in the first 2GB of the process's address space. This flag should have the same semantics as the same flag on Linux. To facilitate this, add a new parameter to vm_map_find() that specifies an optional maximum virtual address. While here, fix several callers of vm_map_find() to use a VMFS_* constant for the findspace argument instead of TRUE and FALSE. Reviewed by: alc Approved by: re (kib)
* Remove the support for using non-mpsafe filesystem modules.kib2012-10-221-4/+1
| | | | | | | | | | | | In particular, do not lock Giant conditionally when calling into the filesystem module, remove the VFS_LOCK_GIANT() and related macros. Stop handling buffers belonging to non-mpsafe filesystems. The VFS_VERSION is bumped to indicate the interface change which does not result in the interface signatures changes. Conducted and reviewed by: attilio Tested by: pho
* Fix found places where uio_resid is truncated to int.kib2012-02-211-1/+2
| | | | | | | | | Add the sysctl debug.iosize_max_clamp, enabled by default. Setting the sysctl to zero allows to perform the SSIZE_MAX-sized i/o requests from the usermode. Discussed with: bde, das (previous versions) MFC after: 1 month
* Fix kernel modules loading for MIPS64 kernel:gonzo2012-01-141-0/+4
| | | | | | | | | | | | | | | | On amd64, link_elf_obj.c must specify KERNBASE rather than VM_MIN_KERNEL_ADDRESS to vm_map_find() because kernel loadable modules must be mapped for execution in the same upper region of the kernel map as the kernel code and data segments. For MIPS32 KERNBASE lies below KVA area (it's less than VM_MIN_KERNEL_ADDRESS) so basically vm_map_find got whole KVA to look through. On MIPS64 it's not the case because KERNBASE is set to the very end of XKSEG, well out of KVA bounds, so vm_map_find always fails. We should use VM_MIN_KERNEL_ADDRESS as a base for vm_map_find. Details obtained from: alc@
* Remove malloc(9) return value checks when M_WAITOK is used.dchagin2011-04-161-26/+0
| | | | MFC after: 2 Week
* Similar to sys/net/vnet.h, define the linker set name for sys/sys/pcpu.hdim2010-11-141-4/+4
| | | | as a macro, and use it instead of literal strings.
* Release the vnode lock and close the linker file vnode earlier inkib2010-10-021-3/+3
| | | | | | | | | the linker_load_file methods. The change is that the consequent linker_file_unload() call is not under the vnode lock anymore. This prevents the LOR between kernel linker sx xlock and vnode lock, because linker_file_unload() relocks kernel linker lock. MFC after: 2 weeks
* completely ignore zero-sized elf sections in modules of elf object type (amd64)avg2010-07-231-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | Current code doesn't check size of elf sections and may perform needless actions of zero-sized memory allocation and similar. The bigger issue is that alignment requirement of a zero-sized section gets effectively applied to the next section if it has smaller alignment requirement. But other tools, like gdb and consequently kgdb, completely ignore zero-sized sections and thus may map symbols to addresses differently. Zero-sized sections are not typical in general. Their typical (only, even) cause in FreeBSD modules is inline assembly that creates custom sections which is found in pcpu.h and vnet.h. Mere inclusion of one of those header files produces a custom section in elf output. If there is no actual use for the section in a given module, then the section remains empty. Better solution is to avoid creating zero-sized sections altogether, which is in plans. Preloaded modules are handled in boot code (load_elf_obj.c), while dynamically loaded modules are handled by kernel (link_elf_obj.c). Based on code by: np MFC after: 3 weeks
* Kernel module support for mips.neel2010-02-181-2/+2
| | | | | | Reviewed by: gonzo Tested by: Alexandr Rybalko (ray@dlink.ua)
* Add macros VNET_SETNAME and VNET_SYMPREFIX, and expose to userspace ifrwatson2009-07-201-4/+4
| | | | | | | | _WANT_VNET is defined. This way we don't need separate definitions in libkvm. Reviewed by: bz Approved by: re (vimage blanket)
* r195699 introduced an assertion regarding when progbits data in kernelrwatson2009-07-151-3/+0
| | | | | | | | | modules was present, which turns out to be false in some situations. Back out the assertion. Reported by: Luiz Otavio O Souza <lists.br at gmail.com>, Florian Smeets <flo at kasimir.com> Approved by: re (kensmith) (implicit)
* Build on Jeff Roberson's linker-set based dynamic per-CPU allocatorrwatson2009-07-141-2/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (DPCPU), as suggested by Peter Wemm, and implement a new per-virtual network stack memory allocator. Modify vnet to use the allocator instead of monolithic global container structures (vinet, ...). This change solves many binary compatibility problems associated with VIMAGE, and restores ELF symbols for virtualized global variables. Each virtualized global variable exists as a "reference copy", and also once per virtual network stack. Virtualized global variables are tagged at compile-time, placing the in a special linker set, which is loaded into a contiguous region of kernel memory. Virtualized global variables in the base kernel are linked as normal, but those in modules are copied and relocated to a reserved portion of the kernel's vnet region with the help of a the kernel linker. Virtualized global variables exist in per-vnet memory set up when the network stack instance is created, and are initialized statically from the reference copy. Run-time access occurs via an accessor macro, which converts from the current vnet and requested symbol to a per-vnet address. When "options VIMAGE" is not compiled into the kernel, normal global ELF symbols will be used instead and indirection is avoided. This change restores static initialization for network stack global variables, restores support for non-global symbols and types, eliminates the need for many subsystem constructors, eliminates large per-subsystem structures that caused many binary compatibility issues both for monitoring applications (netstat) and kernel modules, removes the per-function INIT_VNET_*() macros throughout the stack, eliminates the need for vnet_symmap ksym(2) munging, and eliminates duplicate definitions of virtualized globals under VIMAGE_GLOBALS. Bump __FreeBSD_version and update UPDATING. Portions submitted by: bz Reviewed by: bz, zec Discussed with: gnn, jamie, jeff, jhb, julian, sam Suggested by: peter Approved by: re (kensmith)
* Implement a facility for dynamic per-cpu variables.jeff2009-06-231-10/+50
| | | | | | | | | | | | | | | - Modules and kernel code alike may use DPCPU_DEFINE(), DPCPU_GET(), DPCPU_SET(), etc. akin to the statically defined PCPU_*. Requires only one extra instruction more than PCPU_* and is virtually the same as __thread for builtin and much faster for shared objects. DPCPU variables can be initialized when defined. - Modules are supported by relocating the module's per-cpu linker set over space reserved in the kernel. Modules may fail to load if there is insufficient space available. - Track space available for modules with a one-off extent allocator. Free may block for memory to allocate space for an extent. Reviewed by: jhb, rwatson, kan, sam, grehan, marius, marcel, stas
* strict kobj signatures: linker_if fixesavg2009-06-111-2/+2
| | | | | | | | in symtab_get method symtab parameter is made constant as this reflects actual intention and usage of the method Reviewed by: imp, current@ Approved by: jhb (mentor)
* Move "options MAC" from opt_mac.h to opt_global.h, as it's now in GENERICrwatson2009-06-051-1/+0
| | | | | | | | and used in a large number of files, but also because an increasing number of incorrect uses of MAC calls were sneaking in due to copy-and-paste of MAC-aware code without the associated opt_mac.h include. Discussed with: pjd
* Add the ksyms(4) pseudo driver. The ksyms driver allows a process tosson2009-05-261-0/+30
| | | | | | | | | | | | | | get a quick snapshot of the kernel's symbol table including the symbols from any loaded modules (the symbols are all merged into one symbol table). Unlike like other implementations, this ksyms driver maps memory in the process memory space to store the snapshot at the time /dev/ksyms is opened. It also checks to see if the process has already a snapshot open and won't allow it to open /dev/ksyms it again until it closes first. This prevents kernel and process memory from being exhausted. Note that /dev/ksyms is used by the lockstat(1) command. Reviewed by: gallatin kib (freebsd-arch) Approved by: gnn (mentor)
* Scanning all the formats for binary translation of modules loading canattilio2009-02-101-2/+1
| | | | | | | | | | | | | | | | | | | result in errors for a format loading but subsequent correct recognizing for another format. File format loading functions should avoid printing any additional informations but just returning appropriate (and different between each other) error condition, characterizing different informations. Additively, the linker should handle appropriately different format loading errors. While a general mechanism is desired, fix a simple and common case on amd64: file type is not recognized for link elf and confuses the linker. Printout an error if all the registered linker classes can't recognize and load the module. Reviewed by: jhb Sponsored by: Sandvine Incorporated
* Calling linker_load_dependencies() while holding the module'kib2008-08-031-0/+2
| | | | | | | | | vnode lock may cause a LOR between kld_sx lock and vnode lock. linker_load_dependencies() drops kld_sx, and another thread may attempt to load the same kld. Reported and tested by: pjd MFC after: 1 week
* Improve readability and cscope searches a little bit by not using theobrien2008-07-111-38/+38
| | | | same variable name in closely related (but not conflicting) contexts.
* Improve the output of kldload(8) to show which module can't be loaded.edwin2008-07-081-9/+12
| | | | | | | | | | Was: kldload: Unsupported file type Is now: kldload: /boot/modules/test.ko: Unsupported file type PR: kern/121276 Submitted by: Edwin Groothuis <edwin@mavetju.org> Approved by: bde (mentor) MFC after: 1 week
* Enforce the mapping of kernel loadable modules in the uppermost 2GB of thealc2008-06-201-0/+7
| | | | kernel virtual address space on amd64.
* Add hooks for the Compact C Type Format (CTF) data to be attached tojb2008-05-231-0/+53
| | | | | | the elf files. This is complicated by the fact that the actual CTF parsing has to be done in CDDL'd code, so the BSD licensed code only knows about the opaque data which it must be able to free.
* Fix panic on e.g. "kldload /dev/null".ru2008-03-151-0/+4
| | | | | | PR: kern/121427 Reviewed by: sem MFC after: 3 days
* VOP_LOCK1() (and so VOP_LOCK()) and VOP_UNLOCK() are only used inattilio2008-01-131-1/+1
| | | | | | | | | | | conjuction with 'thread' argument passing which is always curthread. Remove the unuseful extra-argument and pass explicitly curthread to lower layer functions, when necessary. KPI results broken by this change, which should affect several ports, so version bumping and manpage update will be further committed. Tested by: kris, pho, Diego Sardina <siarodx at gmail dot com>
* Merge first in a series of TrustedBSD MAC Framework KPI changesrwatson2007-10-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | from Mac OS X Leopard--rationalize naming for entry points to the following general forms: mac_<object>_<method/action> mac_<object>_check_<method/action> The previous naming scheme was inconsistent and mostly reversed from the new scheme. Also, make object types more consistent and remove spaces from object types that contain multiple parts ("posix_sem" -> "posixsem") to make mechanical parsing easier. Introduce a new "netinet" object type for certain IPv4/IPv6-related methods. Also simplify, slightly, some entry point names. All MAC policy modules will need to be recompiled, and modules not updates as part of this commit will need to be modified to conform to the new KPI. Sponsored by: SPARTA (original patches against Mac OS X) Obtained from: TrustedBSD Project, Apple Computer
* Revert UF_OPENING workaround for CURRENT.kib2007-05-311-1/+1
| | | | | | | | | Change the VOP_OPEN(), vn_open() vnode operation and d_fdopen() cdev operation argument from being file descriptor index into the pointer to struct file. Proposed and reviewed by: jhb Reviewed by: daichi (unionfs) Approved by: re (kensmith)
* Linker set support depends on the magic __start_<section> andkib2006-11-301-0/+47
| | | | | | | | | | | | | __stop_<section> symbols generated by the static linker for elf sections. This is done only for the final link, and not for ld -r. Augment elf_obj in-kernel linker by recognizing such special symbols, and resolving them to the start and end of the section automatically. As result, linker sets on amd64 could be used in the same way as on other architectures, without explicit calls to linker_file_lookup_set(). Requested by: rdivacky No objections from: peter, jhb
* Complete break-out of sys/sys/mac.h into sys/security/mac/mac_framework.hrwatson2006-10-221-1/+2
| | | | | | | | | | | | | begun with a repo-copy of mac.h to mac_framework.h. sys/mac.h now contains the userspace and user<->kernel API and definitions, with all in-kernel interfaces moved to mac_framework.h, which is now included across most of the kernel instead. This change is the first step in a larger cleanup and sweep of MAC Framework interfaces in the kernel, and will not be MFC'd. Obtained from: TrustedBSD Project Sponsored by: SPARTA
* Replace the kld_mtx mutex with a kld_sx sx lock and expand it's scope tojhb2006-06-211-2/+0
| | | | | | | | | | | | protect all linker-related data structures including the contents of linker file objects and the any linker class data as well. Considering how rarely the linker is used I just went with the simple solution of single-threading the whole thing rather than expending a lot of effor on something more fine-grained and complex. Giant is still explicitly acquired while registering and deregistering sysctl's as well as in the elf linker class while calling kmupetext(). The rest of the linker runs without Giant unless it has to acquire Giant while loading files from a non-MPSAFE filesystem.
* Conditionally acquire Giant around VFS operations.jhb2006-06-201-1/+5
|
* Make our ELF64 type definitions match standards. In particular thismarcel2005-12-181-5/+5
| | | | | | | | | | | | | means: o Remove Elf64_Quarter, o Redefine Elf64_Half to be 16-bit, o Redefine Elf64_Word to be 32-bit, o Add Elf64_Xword and Elf64_Sxword for 64-bit entities, o Use Elf_Size in MI code to abstract the difference between Elf32_Word and Elf64_Word. o Add Elf_Ssize as the signed counterpart of Elf_Size. MFC after: 2 weeks
* Handle vm_map_wire()'s failure.alc2005-08-281-1/+5
|
* Eliminate an unneeded reference on a vm object. If, in fact, the nearbyalc2005-08-281-2/+0
| | | | | | | vm_map_find() fails, then the excess reference causes the vm object to be leaked. Reviewed by: tegge
* Add support for completing the installation of ELF relocatableiedowse2004-08-291-3/+208
| | | | | object format modules that were read in by the loader. Loading modules via the loader should now work on the amd64 platform.
* Give kldunload a -f(orce) argument.phk2004-07-131-1/+1
| | | | | | | | | | | | | | | | | Add a MOD_QUIESCE event for modules. This should return error (EBUSY) of the module is in use. MOD_UNLOAD should now only fail if it is impossible (as opposed to inconvenient) to unload the module. Valid reasons are memory references into the module which cannot be tracked down and eliminated. When kldunloading, we abandon if MOD_UNLOAD fails, and if -force is not given, MOD_QUIESCE failing will also prevent the unload. For backwards compatibility, we treat EOPNOTSUPP from MOD_QUIESCE as success. Document that modules should return EOPNOTSUPP for unknown events.
* Wrap long line.peter2004-06-291-1/+3
|
* Change strategy based on a suggestion from Ian Dowse. Instead of tryingpeter2004-06-151-37/+30
| | | | | to keep track of different section base addresses at a symbol-by-symbol level, just set the symbol values at load time.
* Fix symbol lookups between modules. This caused modules that depend onpeter2004-06-151-1/+5
| | | | | | other modules to explode. eg: snd_ich->snd_pcm and umass->usb. The problem was that I was using the unified base address of the module instead of finding the start address of the section in question.
* Insurance: cause a proper symbol lookup failure for symbol entries thatpeter2004-06-151-0/+2
| | | | reference unknown sections.. rather than returning a small value.
* If a symbol has section+offset definitions provided, always use insteadpeter2004-05-181-6/+9
| | | | of doing a name lookup for global symbols. This fixes the snd_pcm module.
* Remove leftover padding variables.peter2004-05-181-8/+4
| | | | | Convert some silent 'ignore programmer error' cases into panics Remove 'align' field from section table (no longer needed)
OpenPOWER on IntegriCloud