[PATCH 1/4] Add missing tests to .gitignore
Some test binaries were missing and showed up in "git status". Signed-off-by: Ulf Hermann --- .gitignore | 12 1 file changed, 12 insertions(+) diff --git a/.gitignore b/.gitignore index c583347..0ee3af7 100644 --- a/.gitignore +++ b/.gitignore @@ -93,6 +93,7 @@ Makefile.in /tests/asm-tst9 /tests/backtrace /tests/backtrace-child +/tests/backtrace-child-biarch /tests/backtrace-data /tests/backtrace-dwarf /tests/buildid @@ -102,18 +103,26 @@ Makefile.in /tests/dwarf-getmacros /tests/dwarf-getstring /tests/dwarf-ranges +/tests/dwelfgnucompressed /tests/dwfl-addr-sect /tests/dwfl-bug-addr-overflow /tests/dwfl-bug-fd-leak /tests/dwfl-bug-getmodules /tests/dwfl-bug-report +/tests/dwfl-proc-attach /tests/dwfl-report-elf-align /tests/dwfllines /tests/dwflmodtest /tests/dwflsyms /tests/early-offscn /tests/ecp +/tests/elfgetchdr +/tests/elfgetzdata +/tests/elfputzdata +/tests/elfshphehdr +/tests/elfstrmerge /tests/elfstrtab +/tests/emptyfile /tests/find-prologues /tests/funcretval /tests/funcscopes @@ -139,6 +148,7 @@ Makefile.in /tests/show-die-info /tests/showptable /tests/strptr +/tests/system-elf-libelf-test /tests/test-elf_cntl_gelf_getshdr /tests/test-flag-nobits /tests/test-nlist @@ -149,5 +159,7 @@ Makefile.in /tests/update3 /tests/update4 /tests/varlocs +/tests/vendorelf /tests/vdsosyms +/tests/zstrptr /version.h -- 2.1.4
[PATCH 2/4] Make the backtrace-data test helper more robust
When unwinding by frame pointer the unwinder might ask for invalid addresses. We don't have to fail the test in this case. In fact any broken dwarf information can lead to requests for invalid addresses, also without frame pointer unwinding. Signed-off-by: Ulf Hermann --- tests/ChangeLog| 6 ++ tests/backtrace-data.c | 16 +--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/ChangeLog b/tests/ChangeLog index 7031cf5..7040ac8 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2017-02-09 Ulf Hermann + + * backtrace-data.c: Don't assert that symbols are found. + The unwinder is allowed to ask for invalid addresses. We deny + such requests, rather than make the test fail. + 2016-11-17 Mark Wielaard * run-readelf-s.sh: Add --symbols=.dynsym and --symbols=.symtab tests. diff --git a/tests/backtrace-data.c b/tests/backtrace-data.c index b7158da..a387d8f 100644 --- a/tests/backtrace-data.c +++ b/tests/backtrace-data.c @@ -76,10 +76,15 @@ memory_read (Dwfl *dwfl, Dwarf_Addr addr, Dwarf_Word *result, errno = 0; long l = ptrace (PTRACE_PEEKDATA, child, (void *) (uintptr_t) addr, NULL); - assert (errno == 0); + + // The unwinder can ask for an invalid address. + // Don't assert on that but just politely refuse. + if (errno != 0) { + errno = 0; + return false; + } *result = l; - /* We could also return false for failed ptrace. */ return true; } @@ -103,7 +108,8 @@ maps_lookup (pid_t pid, Dwarf_Addr addr, GElf_Addr *basep) unsigned long start, end, offset; i = fscanf (f, "%lx-%lx %*s %lx %*x:%*x %*x", &start, &end, &offset); assert (errno == 0); - assert (i == 3); + if (i != 3) + break; char *filename = strdup (""); assert (filename); size_t filename_len = 0; @@ -131,6 +137,8 @@ maps_lookup (pid_t pid, Dwarf_Addr addr, GElf_Addr *basep) } free (filename); } + *basep = 0; + return NULL; } /* Add module containing ADDR to the DWFL address space. @@ -145,6 +153,8 @@ report_module (Dwfl *dwfl, pid_t child, Dwarf_Addr addr) { GElf_Addr base; char *long_name = maps_lookup (child, addr, &base); + if (!long_name) + return NULL; // not found Dwfl_Module *mod = dwfl_report_elf (dwfl, long_name, long_name, -1, base, false /* add_p_vaddr */); assert (mod); -- 2.1.4
[PATCH 3/4] Optionally allow unknown symbols in the backtrace tests
This is useful to test unwinding without debug information. The binaries being examined might still have frame pointers that allow us to bridge the unknown symbols. Signed-off-by: Ulf Hermann --- tests/ChangeLog | 6 ++ tests/backtrace-subr.sh | 14 ++ tests/backtrace.c | 30 ++ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/tests/ChangeLog b/tests/ChangeLog index 7040ac8..bca47be 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,5 +1,11 @@ 2017-02-09 Ulf Hermann + * backtrace.c: Add an option to allow unknown symbols in the trace + * backtrace-substr.sh: Add an option to allow unknown symbols + to check_core() and allow failed symbol lookups in check_err() + +2017-02-09 Ulf Hermann + * backtrace-data.c: Don't assert that symbols are found. The unwinder is allowed to ask for invalid addresses. We deny such requests, rather than make the test fail. diff --git a/tests/backtrace-subr.sh b/tests/backtrace-subr.sh index 790b4f4..5d3937c 100644 --- a/tests/backtrace-subr.sh +++ b/tests/backtrace-subr.sh @@ -44,9 +44,12 @@ check_gsignal() # In some cases we cannot reliably find out we got behind _start as some # operating system do not properly terminate CFI by undefined PC. # Ignore it here as it is a bug of OS, not a bug of elfutils. +# If the CFI is not terminated correctly, we might find another frame by +# checking for frame pointers. This is still not our problem, but only +# gives an error message when trying to look up the function name. check_err() { - if [ $(egrep -v <$1 'dwfl_thread_getframes: (No DWARF information found|no matching address range)$' \ + if [ $(egrep -v <$1 'dwfl_thread_getframes: (No DWARF information found|no matching address range|address out of range)$' \ | wc -c) \ -eq 0 ] then @@ -61,7 +64,9 @@ check_all() bt=$1 err=$2 testname=$3 - check_main $bt $testname + if [ "x$4" != "x--allow-unknown" ]; then +check_main $bt $testname + fi check_gsignal $bt $testname check_err $err $testname } @@ -98,13 +103,14 @@ check_native_unsupported() check_core() { arch=$1 + args=$2 testfiles backtrace.$arch.{exec,core} tempfiles backtrace.$arch.{bt,err} echo ./backtrace ./backtrace.$arch.{exec,core} - testrun ${abs_builddir}/backtrace -e ./backtrace.$arch.exec --core=./backtrace.$arch.core 1>backtrace.$arch.bt 2>backtrace.$arch.err || true + testrun ${abs_builddir}/backtrace $args -e ./backtrace.$arch.exec --core=./backtrace.$arch.core 1>backtrace.$arch.bt 2>backtrace.$arch.err || true cat backtrace.$arch.{bt,err} check_unsupported backtrace.$arch.err backtrace.$arch.core - check_all backtrace.$arch.{bt,err} backtrace.$arch.core + check_all backtrace.$arch.{bt,err} backtrace.$arch.core $args } # Backtrace live process. diff --git a/tests/backtrace.c b/tests/backtrace.c index 1ff6353..34a2ab0 100644 --- a/tests/backtrace.c +++ b/tests/backtrace.c @@ -64,6 +64,7 @@ dump_modules (Dwfl_Module *mod, void **userdata __attribute__ ((unused)), return DWARF_CB_OK; } +static bool allow_unknown; static bool use_raise_jmp_patching; static pid_t check_tid; @@ -78,7 +79,8 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc, seen_main = true; if (pc == 0) { - assert (seen_main); + if (!allow_unknown) +assert (seen_main); return; } if (check_tid == 0) @@ -103,11 +105,12 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc, && (strcmp (symname, "__kernel_vsyscall") == 0 || strcmp (symname, "__libc_do_syscall") == 0)) reduce_frameno = true; - else + else if (!allow_unknown || symname) assert (symname && strcmp (symname, "raise") == 0); break; case 1: - assert (symname != NULL && strcmp (symname, "sigusr2") == 0); + if (!allow_unknown || symname) +assert (symname != NULL && strcmp (symname, "sigusr2") == 0); break; case 2: // x86_64 only /* __restore_rt - glibc maybe does not have to have this symbol. */ @@ -116,20 +119,24 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc, if (use_raise_jmp_patching) { /* Verify we trapped on the very first instruction of jmp. */ - assert (symname != NULL && strcmp (symname, "jmp") == 0); + if (!allow_unknown || symname) +assert (symname != NULL && strcmp (symname, "jmp") == 0); mod = dwfl_addrmodule (dwfl, pc - 1); if (mod) symname2 = dwfl_module_addrname (mod, pc - 1); - assert (symname2 == NULL || strcmp (symname2, "jmp") != 0); + if (!allow_unknown || symname2) +
Re: [PATCH 3/4] Optionally allow unknown symbols in the backtrace tests
Hi, I have another patch here, that introduces the actual feature; a fallback mode for unwinding by frame pointer if unwinding by cfi fails. Unfortunately your mail server thinks it's spam, presumably because of the inline test binaries. What can I do about that? br, Ulf Hermann
Re: [PATCH 3/4] Optionally allow unknown symbols in the backtrace tests
Unfortunately your mail server thinks it's spam, presumably because of the inline test binaries. What can I do about that? Do you have the bounce message, then we can investigate. Otherwise could you post the patch without the test binaries? Then we get them some other way. The bounce message is somewhat messy, containing inline html and attachments. This is a somewhat readable text representation: Your message to elfutils-devel@sourceware.org couldn't be delivered. sourceware.org suspects your message is spam and rejected it. ulf.hermann Office 365 sourceware.org Sender Action Required Messages suspected as spam How to Fix It Try to modify your message, or change how you're sending the message, using the guidance in this article: Bulk E-mailing Best Practices for Senders Using Forefront Online Protection for Exchange. Then resend your message. If you continue to experience the problem, contact the recipient by some other means (by phone, for example) and ask them to ask their email admin to add your email address, or your domain name, to their allowed senders list. Was this helpful? Send feedback to Microsoft. More Info for Email Admins Status code: 550 5.7.350 When Office 365 tried to send the message to the recipient (outside Office 365), the recipient's email server (or email filtering service) suspected the sender's message is spam. If the sender can't fix the problem by modifying their message, contact the recipient's email admin and ask them to add your domain name, or the sender's email address, to their list of allowed senders. Although the sender may be able to alter the message contents to fix this issue, it's likely that only the recipient's email admin can fix this problem. Unfortunately, Office 365 Support is unlikely to be able to help fix these kinds of externally reported errors. Original Message Details Created Date: 2/10/2017 2:20:21 PM Sender Address: ulf.herm...@qt.io Recipient Address: elfutils-devel@sourceware.org Subject:[PATCH 4/4] Add frame pointer unwinding as fallback on x86_64 Error Details Reported error: 550 5.7.350 Remote server returned message detected as spam -> 552 spam score exceeded threshold DSN generated by: VI1PR0201MB1869.eurprd02.prod.outlook.com Remote server: sourceware.org Message Hops HOP TIME (UTC) FROMTO WITHRELAY TIME 1 2/10/2017 2:20:22 PM [10.9.78.60]VI1PR0201MB1869.eurprd02.prod.outlook.com Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) 1 sec Original Message Headers DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qtcompany.onmicrosoft.com; s=selector1-qt-io; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=j1DH0w0/pXTH2S/0HIhEj4Ruuawzgt1pBNwl4lbKAqU=; b=F8/u6gSVjlPl4d34hVp3S0ehZJGze8mXCGjPHO++IwhFa61XiFtanOSgXWvVgEgeRAv4sdbP3Dx0J3Q32sJFUdkdUMP7qg9ea+2SGGeCX5/aUvxOCFZqcT1bdRFyIfAURQNNPHSGaTk9IsaFb4n6VhZWwKBV0RD3P5G1b//DpLA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ulf.herm...@qt.io; Received: from [10.9.78.60] (62.220.2.194) by VI1PR0201MB1869.eurprd02.prod.outlook.com (10.167.206.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.888.16; Fri, 10 Feb 2017 14:20:22 + From: Ulf Hermann Subject: [PATCH 4/4] Add frame pointer unwinding as fallback on x86_64 To: Message-ID: <6007c160-b26f-a757-d00b-d40b4c582...@qt.io> Date: Fri, 10 Feb 2017 15:20:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [62.220.2.194] X-ClientProxiedBy: DB5PR03CA0083.eurprd03.prod.outlook.com (10.164.34.51) To VI1PR0201MB1869.eurprd02.prod.outlook.com (10.167.206.147) Return-Path: ulf.herm...@qt.io X-MS-Office365-Filtering-Correlation-Id: ec09c7eb-12da-48b3-ab58-08d451bff373 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:VI1PR0201MB1869; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0201MB1869;3:R1nBXKiZxfHImwXYgHnoCPlwj548vce+nOHis8TgdLGSGnWq5EpPzVdJg4gykOxZ76C0AQs+CdNH+WCTGZ52qcic1z3f8trei8HMHtrcRYK4DyWEWjzujBCtD+ckfl4r+8iYRtAVkOcnrWCTK951whAvXK9QpZYjO3LuLsfOaVAzsjwq1hYSCtcsjFSUUkswBvZNkkCmUwYdckggdmLTN7IpgyUQN3KLo6+IDtn9tuvmcVJk//HmpelY1wFN3XFeJGcRbyzGYFucG4+ETmhRww==;25:PW9H6AvU67yyWrJz4zsRyDMdEgQSeVltnnJvsN/Vs7hGTdQ5EZd6xRVKlQ3v1QaD6KNjU+rgPp4BbbI/swQOWx1DjztURFfPqmaDWAxLeBI+djpCH9Dp+MQH7sPPSQyHCeW0FU0Rxg+5o4Wh8JQaidmKe3DrUyN0OW/9N6qw9XcS7+d7TeyhXBI6jVSBTstqhe8L3M8x7XD49aIHGOIkMrEIKPxo18ht6Xrgt5yhp2pv7HqDEaKoBYZbh7nNYIdmIUhnjuTC6P3ROIPqyNoidVEleaSzL4ATISomo6IWWx6bMtVFm3Ci5BDPM08CPzWak6u/FhQifXqnfO14RP03qY9q377tksmbHyxmiEhgP1FStP3vFd/u43XbkeyRVXA1RES12WTWhwlXPKVHQCqmWajEPkXYEMa
Re: [PATCH 3/4] Optionally allow unknown symbols in the backtrace tests
Try sending suspicious content via something like fpaste.org. I don't think it's very suspicious, but I don't intend to start a pointless argument as first thing I do here ;) fpaste.org won't accept it either, but paste.kde.org does. So, here we go: https://paste.kde.org/pgs6oqk2z br, Ulf Hermann
Re: [PATCH 3/4] Optionally allow unknown symbols in the backtrace tests
Thanks for pointing out the issues. I will track down the white space problem. I could reconstruct it from that pastebin. But it was a bit of a struggle, some parts didn't apply as is because tabs seemed to be turned into spaces. I tried to repost it to the list. But the first time it was bounced as "spam" and the second time after removing the git-bin-diffs sourceware seemed to accept it, but then it never showed up on the list. (See below for the logs on my end.) I have the same frame pointer unwinding fallbacks for arm and arm64 in the elfutils bundled with perfparser. I just need to write test cases for them, then I will post them, too. So, it's probably a good idea to either have the mailing list accept patches with inline binaries or allow some other channel of patch submission. br, Ulf
Re: [PATCH 3/4] Optionally allow unknown symbols in the backtrace tests
I didn't know about perfparse. I assume that is this code base: http://code.qt.io/cgit/qt-creator/perfparser.git/ Very nice. Yes. I'm also trying to port this to windows. So, I have lots of changes to make the code more portable: https://codereview.qt-project.org/#/c/184401/ and the 50 changes depending on that. I will try to get those into an acceptable form and post them here. Please feel free to sent the commit (with git send-email) to me and I can add them to a review branch in elfutils.git so others can review them easily. Or if you already have them in your own git tree feel free to sent the commits to review/pull to the list. And we can pull them from there. I assume this must be the patch that adds the arm64 support: http://code.qt.io/cgit/qt-creator/perfparser.git/commit/3rdparty/elfutils?id=17ad3b57d613fede17a01b6cdd2d894850364f81 In principle yes. However, perfparser doesn't include elfutils' test framework and writing the tests I've found some problems with the frame pointer unwinders. So don't just take that commit ... I'll send the new versions to you personally. regards, Ulf
[PATCH] Move color handling into a separate header
We only need it in nm.c and objdump.c, but it pulls in argp as dependency. By dropping it from libeu.h, the libraries can be compiled without argp. Signed-off-by: Ulf Hermann --- lib/ChangeLog | 7 +++ lib/Makefile.am | 2 +- lib/color.c | 2 +- lib/color.h | 63 + lib/libeu.h | 32 - src/ChangeLog | 5 + src/nm.c| 1 + src/objdump.c | 1 + 8 files changed, 79 insertions(+), 34 deletions(-) create mode 100644 lib/color.h diff --git a/lib/ChangeLog b/lib/ChangeLog index fcf5b10..5ccf4d6 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,10 @@ +2017-02-14 Ulf Hermann + + * color.h: New file. + * color.c: Include color.h. + * libeu.h: Remove color handling. + * Makefile.am (noinst_HEADERS): Add color.h. + 2016-12-29 Luiz Angelo Daros de Luca * crc32_file.c: Include system.h. diff --git a/lib/Makefile.am b/lib/Makefile.am index 1ad9ce8..3e0c601 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -38,7 +38,7 @@ libeu_a_SOURCES = xstrdup.c xstrndup.c xmalloc.c next_prime.c \ color.c version.c noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \ -md5.h sha1.h eu-config.h +md5.h sha1.h eu-config.h color.h EXTRA_DIST = dynamicsizehash.c if !GPROF diff --git a/lib/color.c b/lib/color.c index fde2d9d..f62389d 100644 --- a/lib/color.c +++ b/lib/color.c @@ -38,7 +38,7 @@ #include #include #include "libeu.h" - +#include "color.h" /* Prototype for option handler. */ static error_t parse_opt (int key, char *arg, struct argp_state *state); diff --git a/lib/color.h b/lib/color.h new file mode 100644 index 000..3872eb0 --- /dev/null +++ b/lib/color.h @@ -0,0 +1,63 @@ +/* Handling of color output. + Copyright (C) 2017 The Qt Company + This file is part of elfutils. + Written by Ulrich Drepper , 2011. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + elfutils 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 copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see <http://www.gnu.org/licenses/>. */ + + +#ifndef COLOR_H +#define COLOR_H 1 + +/* Command line parser. */ +extern const struct argp color_argp; + +/* Coloring mode. */ +enum color_enum + { +color_never = 0, +color_always, +color_auto + } __attribute__ ((packed)); +extern enum color_enum color_mode; + +/* Colors to use for the various components. */ +extern char *color_address; +extern char *color_bytes; +extern char *color_mnemonic; +extern char *color_operand1; +extern char *color_operand2; +extern char *color_operand3; +extern char *color_label; +extern char *color_undef; +extern char *color_undef_tls; +extern char *color_undef_weak; +extern char *color_symbol; +extern char *color_tls; +extern char *color_weak; + +extern const char color_off[]; + +#endif /* color.h */ diff --git a/lib/libeu.h b/lib/libeu.h index 69fe3d7..ecb4d01 100644 --- a/lib/libeu.h +++ b/lib/libeu.h @@ -43,36 +43,4 @@ extern char *xstrndup (const char *, size_t) __attribute__ ((__malloc__)); extern uint32_t crc32 (uint32_t crc, unsigned char *buf, size_t len); extern int crc32_file (int fd, uint32_t *resp); - -/* Color handling. */ - -/* Command line parser. */ -extern const struct argp color_argp; - -/* Coloring mode. */ -enum color_enum - { -color_never = 0, -color_always, -color_auto - } __attribute__ ((packed)); -extern enum color_enum color_mode; - -/* Colors to use for the various components. */ -extern char *color_address; -extern char *color_bytes; -extern char *color_mnemonic; -extern char *color_operand1; -extern char *color_operand2; -extern char *color_operand3; -extern char *color_label; -extern char *color_undef; -extern char *color_undef_tls; -extern char *color_undef_weak; -extern char *color_symbol; -extern char *color_tls; -extern char *color_weak; - -extern const char color_off[]; - #endif diff --git a/src/ChangeLog b/src/ChangeLog index 2a6d93e..19c7dbb 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2017-02-14 Ulf Hermann + + * nm.c: Include color.h. + * objdump.
[PATCH] Always use the same method to query the system page size
This makes it easier to write a replacement for it on systems where sysconf(3) doesn't exist. --- lib/ChangeLog | 4 lib/crc32_file.c | 2 +- libdwfl/ChangeLog | 5 + libdwfl/linux-kernel-modules.c | 2 +- libdwfl/linux-proc-maps.c | 2 +- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 5ccf4d6..6578ddb 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,7 @@ +2017-02-15 Ulf Hermann + + * crc32_file.c: Use _SC_PAGESIZE rather than _SC_PAGE_SIZE. + 2017-02-14 Ulf Hermann * color.h: New file. diff --git a/lib/crc32_file.c b/lib/crc32_file.c index 57e4298..f7607d0 100644 --- a/lib/crc32_file.c +++ b/lib/crc32_file.c @@ -53,7 +53,7 @@ crc32_file (int fd, uint32_t *resp) void *mapped = mmap (NULL, mapsize, PROT_READ, MAP_PRIVATE, fd, 0); if (mapped == MAP_FAILED && errno == ENOMEM) { - const size_t pagesize = sysconf (_SC_PAGE_SIZE); + const size_t pagesize = sysconf (_SC_PAGESIZE); mapsize = ((mapsize / 2) + pagesize - 1) & -pagesize; while (mapsize >= pagesize && (mapped = mmap (NULL, mapsize, PROT_READ, MAP_PRIVATE, diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 57671ea..52466cc 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,8 @@ +2017-02-15 Ulf Hermann + + * linux-kernel-modules.c: Use sysconf(_SC_PAGESIZE) to get page size. + * linux-proc-maps.c: Likewise. + 2016-12-29 Luiz Angelo Daros de Luca * dwfl_build_id_find_elf.c: Include system.h. diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c index 9cd8ea9..a7ac19d 100644 --- a/libdwfl/linux-kernel-modules.c +++ b/libdwfl/linux-kernel-modules.c @@ -500,7 +500,7 @@ intuit_kernel_bounds (Dwarf_Addr *start, Dwarf_Addr *end, Dwarf_Addr *notes) if (*notes == 0 && !strcmp (state.p, "__start_notes\n")) *notes = *end; - Dwarf_Addr round_kernel = sysconf (_SC_PAGE_SIZE); + Dwarf_Addr round_kernel = sysconf (_SC_PAGESIZE); *start &= -(Dwarf_Addr) round_kernel; *end += round_kernel - 1; *end &= -(Dwarf_Addr) round_kernel; diff --git a/libdwfl/linux-proc-maps.c b/libdwfl/linux-proc-maps.c index 4ae1e74..094dd53 100644 --- a/libdwfl/linux-proc-maps.c +++ b/libdwfl/linux-proc-maps.c @@ -418,7 +418,7 @@ dwfl_linux_proc_find_elf (Dwfl_Module *mod __attribute__ ((unused)), if (fd < 0) goto detach; - *elfp = elf_from_remote_memory (base, getpagesize (), NULL, + *elfp = elf_from_remote_memory (base, sysconf (_SC_PAGESIZE), NULL, &read_proc_memory, &fd); close (fd); -- 2.1.4
[PATCH v2] Always use the same method to query the system page size
This makes it easier to write a replacement for it on systems where sysconf(3) doesn't exist. Signed-off-by: Ulf Hermann --- lib/ChangeLog | 4 lib/crc32_file.c | 2 +- libdwfl/ChangeLog | 5 + libdwfl/linux-kernel-modules.c | 2 +- libdwfl/linux-proc-maps.c | 2 +- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 5ccf4d6..6578ddb 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,7 @@ +2017-02-15 Ulf Hermann + + * crc32_file.c: Use _SC_PAGESIZE rather than _SC_PAGE_SIZE. + 2017-02-14 Ulf Hermann * color.h: New file. diff --git a/lib/crc32_file.c b/lib/crc32_file.c index 57e4298..f7607d0 100644 --- a/lib/crc32_file.c +++ b/lib/crc32_file.c @@ -53,7 +53,7 @@ crc32_file (int fd, uint32_t *resp) void *mapped = mmap (NULL, mapsize, PROT_READ, MAP_PRIVATE, fd, 0); if (mapped == MAP_FAILED && errno == ENOMEM) { - const size_t pagesize = sysconf (_SC_PAGE_SIZE); + const size_t pagesize = sysconf (_SC_PAGESIZE); mapsize = ((mapsize / 2) + pagesize - 1) & -pagesize; while (mapsize >= pagesize && (mapped = mmap (NULL, mapsize, PROT_READ, MAP_PRIVATE, diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 57671ea..52466cc 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,8 @@ +2017-02-15 Ulf Hermann + + * linux-kernel-modules.c: Use sysconf(_SC_PAGESIZE) to get page size. + * linux-proc-maps.c: Likewise. + 2016-12-29 Luiz Angelo Daros de Luca * dwfl_build_id_find_elf.c: Include system.h. diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c index 9cd8ea9..a7ac19d 100644 --- a/libdwfl/linux-kernel-modules.c +++ b/libdwfl/linux-kernel-modules.c @@ -500,7 +500,7 @@ intuit_kernel_bounds (Dwarf_Addr *start, Dwarf_Addr *end, Dwarf_Addr *notes) if (*notes == 0 && !strcmp (state.p, "__start_notes\n")) *notes = *end; - Dwarf_Addr round_kernel = sysconf (_SC_PAGE_SIZE); + Dwarf_Addr round_kernel = sysconf (_SC_PAGESIZE); *start &= -(Dwarf_Addr) round_kernel; *end += round_kernel - 1; *end &= -(Dwarf_Addr) round_kernel; diff --git a/libdwfl/linux-proc-maps.c b/libdwfl/linux-proc-maps.c index 4ae1e74..094dd53 100644 --- a/libdwfl/linux-proc-maps.c +++ b/libdwfl/linux-proc-maps.c @@ -418,7 +418,7 @@ dwfl_linux_proc_find_elf (Dwfl_Module *mod __attribute__ ((unused)), if (fd < 0) goto detach; - *elfp = elf_from_remote_memory (base, getpagesize (), NULL, + *elfp = elf_from_remote_memory (base, sysconf (_SC_PAGESIZE), NULL, &read_proc_memory, &fd); close (fd); -- 2.1.4
[PATCH] Check for existence of mempcpy
If it doesn't exist, provide a definition based on memcpy. Signed-off-by: Ulf Hermann --- ChangeLog | 4 configure.ac | 3 +++ lib/ChangeLog | 5 + lib/system.h | 5 + lib/xstrndup.c | 2 +- libasm/ChangeLog | 4 libasm/disasm_str.c| 2 +- libdwfl/ChangeLog | 4 libdwfl/linux-kernel-modules.c | 1 + libebl/ChangeLog | 5 + libebl/eblmachineflagname.c| 1 + libebl/eblopenbackend.c| 1 + tests/ChangeLog| 4 tests/elfstrmerge.c| 1 + 14 files changed, 40 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b50f79e..48185c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-02-15 Ulf Hermann + + * configure.ac: Add check for mempcpy. + 2017-02-09 Mark Wielaard * configure.ac: Add check for adding -D_FORTIFY_SOURCE=2 to CFLAGS. diff --git a/configure.ac b/configure.ac index 46055f2..3c35dac 100644 --- a/configure.ac +++ b/configure.ac @@ -285,6 +285,9 @@ AC_CHECK_DECLS([memrchr, rawmemchr],[],[], [#define _GNU_SOURCE #include ]) AC_CHECK_DECLS([powerof2],[],[],[#include ]) +AC_CHECK_DECLS([mempcpy],[],[], + [#define _GNU_SOURCE +#include ]) AC_CHECK_LIB([stdc++], [__cxa_demangle], [dnl AC_DEFINE([USE_DEMANGLE], [1], [Defined if demangling is enabled])]) diff --git a/lib/ChangeLog b/lib/ChangeLog index 6578ddb..fd63e03 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,5 +1,10 @@ 2017-02-15 Ulf Hermann + * system.h: Provide mempcpy if it doesn't exist. + * xstrndup.c: Include system.h. + +2017-02-15 Ulf Hermann + * crc32_file.c: Use _SC_PAGESIZE rather than _SC_PAGE_SIZE. 2017-02-14 Ulf Hermann diff --git a/lib/system.h b/lib/system.h index dde7c4a..429b0c3 100644 --- a/lib/system.h +++ b/lib/system.h @@ -68,6 +68,11 @@ #define powerof2(x) (((x) & ((x) - 1)) == 0) #endif +#if !HAVE_DECL_MEMPCPY +#define mempcpy(dest, src, n) \ +((void *) ((char *) memcpy (dest, src, n) + (size_t) n)) +#endif + /* A special gettext function we use if the strings are too short. */ #define sgettext(Str) \ ({ const char *__res = strrchr (gettext (Str), '|'); \ diff --git a/lib/xstrndup.c b/lib/xstrndup.c index d43e3b9..a257aa9 100644 --- a/lib/xstrndup.c +++ b/lib/xstrndup.c @@ -33,7 +33,7 @@ #include #include #include "libeu.h" - +#include "system.h" /* Return a newly allocated copy of STRING. */ char * diff --git a/libasm/ChangeLog b/libasm/ChangeLog index fe06007..26fc5a9 100644 --- a/libasm/ChangeLog +++ b/libasm/ChangeLog @@ -1,3 +1,7 @@ +2017-02-15 Ulf Hermann + + * disasm_str.c: Include system.h. + 2015-10-11 Akihiko Odaki * asm_align.c: Remove sys/param.h include. diff --git a/libasm/disasm_str.c b/libasm/disasm_str.c index 5b0bb29..c14e6d5 100644 --- a/libasm/disasm_str.c +++ b/libasm/disasm_str.c @@ -31,7 +31,7 @@ #endif #include - +#include #include "libasmP.h" diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 52466cc..4c9f4f6 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,5 +1,9 @@ 2017-02-15 Ulf Hermann + * linux-kernel-modules.c: Include system.h. + +2017-02-15 Ulf Hermann + * linux-kernel-modules.c: Use sysconf(_SC_PAGESIZE) to get page size. * linux-proc-maps.c: Likewise. diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c index a7ac19d..7345e76 100644 --- a/libdwfl/linux-kernel-modules.c +++ b/libdwfl/linux-kernel-modules.c @@ -34,6 +34,7 @@ #endif #include +#include #include "libdwflP.h" #include diff --git a/libebl/ChangeLog b/libebl/ChangeLog index 0560c6a..719d08d 100644 --- a/libebl/ChangeLog +++ b/libebl/ChangeLog @@ -1,3 +1,8 @@ +2017-02-15 Ulf Hermann + + * eblmachineflagname.c: Include system.h. + * eblopenbackend.c: Likewise. + 2016-07-08 Mark Wielaard * Makefile.am (gen_SOURCES): Remove eblstrtab.c. diff --git a/libebl/eblmachineflagname.c b/libebl/eblmachineflagname.c index 6079a61..5f44077 100644 --- a/libebl/eblmachineflagname.c +++ b/libebl/eblmachineflagname.c @@ -33,6 +33,7 @@ #include #include +#include #include diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c index aa75b95..f3a65cf 100644 --- a/libebl/eblopenbackend.c +++ b/libebl/eblopenbackend.c @@ -39,6 +39,7 @@ #include #include +#include #include diff --git a/tests/ChangeLog b/tests/ChangeLog index 71dba42..4af450c 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,7 @@ +2017-02-15 Ulf Hermann + + * elfstrmerge.c: Include system.h. + 2017-02-13 Ulf Hermann * Makefile.am: Add test for unwinding with frame pointers on aarch64 diff --git a/
Re: frame unwinding patches
> I had to hand apply a few things because of whitespace adjustments. > Hopefully I did it right and this is how Ulf intended the patches. > If not, my apologies, and please let me know what changes you did > intend. Thank you. The patches are correct. cheers, Ulf
[PATCH] Move print_version into printversion.{h|c}
Rename version.c so that the implementation is called after the header and the header doesn't clash with the toplevel version.h. print_version depends on argp and is only used in the tools. Signed-off-by: Ulf Hermann --- lib/ChangeLog | 13 + lib/Makefile.am| 4 ++-- lib/printversion.c | 45 + lib/printversion.h | 49 + lib/system.h | 16 lib/version.c | 47 --- po/ChangeLog | 4 po/POTFILES.in | 2 +- src/ChangeLog | 18 ++ src/addr2line.c| 1 + src/ar.c | 1 + src/elfcmp.c | 2 +- src/elfcompress.c | 2 +- src/elflint.c | 1 + src/findtextrel.c | 2 +- src/nm.c | 1 + src/objdump.c | 1 + src/ranlib.c | 1 + src/readelf.c | 1 + src/size.c | 2 +- src/stack.c| 1 + src/strings.c | 1 + src/strip.c| 1 + src/unstrip.c | 2 +- 24 files changed, 147 insertions(+), 71 deletions(-) create mode 100644 lib/printversion.c create mode 100644 lib/printversion.h delete mode 100644 lib/version.c diff --git a/lib/ChangeLog b/lib/ChangeLog index fd63e03..84290f7 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,16 @@ +2017-02-16 Ulf Hermann + + * Makefile.am (libeu_a_SOURCES): Remove version.c, add printversion.c + (noinst_HEADERS): Add printversion.h + * version.c: Moved to printversion.c. + * printversion.c: New file, moved from version.c, + remove stdio.h, argp.h, system.h includes, + add printversion.h include. + * printversion.h: New file. + * system.h: Remove argp.h include, + (ARGP_PROGRAM_VERSION_HOOK_DEF, ARGP_PROGRAM_BUG_ADDRESS_DEF): Remove. + (print_version): Remove. + 2017-02-15 Ulf Hermann * system.h: Provide mempcpy if it doesn't exist. diff --git a/lib/Makefile.am b/lib/Makefile.am index 3e0c601..7a65eb9 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -35,10 +35,10 @@ noinst_LIBRARIES = libeu.a libeu_a_SOURCES = xstrdup.c xstrndup.c xmalloc.c next_prime.c \ crc32.c crc32_file.c md5.c sha1.c \ - color.c version.c + color.c printversion.c noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \ -md5.h sha1.h eu-config.h color.h +md5.h sha1.h eu-config.h color.h printversion.h EXTRA_DIST = dynamicsizehash.c if !GPROF diff --git a/lib/printversion.c b/lib/printversion.c new file mode 100644 index 000..4056b93 --- /dev/null +++ b/lib/printversion.c @@ -0,0 +1,45 @@ +/* Common argp_print_version_hook for all tools. + Copyright (C) 2016 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + elfutils 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 copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include "printversion.h" + +void +print_version (FILE *stream, struct argp_state *state) +{ + fprintf (stream, "%s (%s) %s\n", state->name, PACKAGE_NAME, PACKAGE_VERSION); + fprintf (stream, gettext ("\ +Copyright (C) %s The elfutils developers <%s>.\n\ +This is free software; see the source for copying conditions. There is NO\n\ +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ +"), "2016", PACKAGE_URL); +} diff --git a/lib/printversion.h b/lib/printversion.h new file mode 100644 index 000..a9e059f --- /dev/null +++ b/lib/printversion.h @@ -0,0 +1,49 @@ +/* Common argp_print_version_hook for all tools. + Copyright (C) 2017 The Qt Company Ltd. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public Lic
Re: [PATCH] Check for existence of mempcpy
On 02/17/2017 10:46 AM, Mark Wielaard wrote: > On Thu, 2017-02-16 at 10:10 +0100, Ulf Hermann wrote: >> If it doesn't exist, provide a definition based on memcpy. > > Applied, but slightly reluctantly. I have no way to test this. And it > will evaluate the last argument (n) twice. Which seems to not matter in > the current calls in our codebase. But it might subtly break something > if someone forgets. True. With other missing functions I tend to conditionally build the replacements into libeu.a as actual functions. That requires libeu.a to be linked into libdw.so, libelf.so, etc. I will create a followup patch that does the same with mempcpy. Ulf
Re: [PATCH] Check for existence of mempcpy
> If at all possible I would like elfutils to not turn into some > abstraction layer for broken non-GNU/Linux systems. I don't mind small > (mostly) obvious correct defines/checks or tweaks to help out people > using such broken systems. But if we need a lot more of these things I > think we should look if we can just import the necessary gnulib modules > to get portability functions. I've actually done that, but the amount of stuff that would need to be imported is staggering (see for example https://codereview.qt-project.org/#/c/182654/13) and comes with a serious mess of different licenses. I've since switched to a different strategy where I rather disable features than import large gnulib modules. Disabling maintainer mode (for obstack) and any code that uses argp certainly helps. The remaining pain point is tsearch/tfind/tdelete/tdestroy for which we probably need third party code. Another problem is that we need fts for dwfl_linux_kernel_*. I'm on the edge on whether to include the gnulib implementation or disable it. The retrying I/O functions can be implemented on top of either Linux/GNU or windows API and I would just move them to a separate file which I can replace based on availability of one or the other (I don't need to upstream the windows implementation). This technique will require universally using the retrying variants rather than the plain ones, which is a good thing anyway. Replacements for mmap() and dlopen() on windows are a somewhat more involved matter but I don't really need to upstream them either, if you don't want them. All other missing functions are just a few lines of C code each, which can either be pulled from gnulib or reimplemented. As I didn't want to taint myself with license problems I chose to reimplement them for now. But that can be decided on a case by case basis. Those are the patches I'm going to focus on next. And then there are nonstandard C constructs, especially void* arithmetics and statement expressions, which I would like to replace with standards compliant C. That is a somewhat larger and not yet finished project, and I'm hoping you're generally open to it. cheers, Ulf
Re: [PATCH] Move print_version into printversion.{h|c}
> But like said before argp is needed for the tools and the libdw > interface. If your glibc replacement doesn't provide argp the build > should pick up libargp and get the definitions and implementation from > there. libdw only needs it for argument parsing, which we can disable if argp isn't available. Not being able to build the tools in that case isn't the end of the world either. We're can still get a perfectly functional libdw and libelf. I would really like to cut down on dependencies rather than add extra third party code. Ulf
[PATCH] Unify linking of libasm, libelf, libdw, backends
Link them all with -z,defs,-z,relro,--no-undefined, provide complete dependencies for the link steps, and add libeu.a to each one. libeu.a contains useful library functionality that each of them might use. The linker will strip unneeded symbols, so linking it in won't hurt even if none of the functions are used. Signed-off-by: Ulf Hermann --- backends/Makefile.am | 7 --- libasm/Makefile.am | 14 -- libdw/Makefile.am| 15 +-- libelf/Makefile.am | 14 +- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/backends/Makefile.am b/backends/Makefile.am index bfb6b84..79bd26c 100644 --- a/backends/Makefile.am +++ b/backends/Makefile.am @@ -45,6 +45,7 @@ noinst_DATA = $(libebl_pic:_pic.a=.so) libelf = ../libelf/libelf.so libdw = ../libdw/libdw.so +libeu = ../lib/libeu.a i386_SRCS = i386_init.c i386_symbol.c i386_corenote.c i386_cfi.c \ i386_retval.c i386_regs.c i386_auxv.c i386_syscall.c \ @@ -130,14 +131,14 @@ libebl_bpf_pic_a_SOURCES = $(bpf_SRCS) am_libebl_bpf_pic_a_OBJECTS = $(bpf_SRCS:.c=.os) -libebl_%.so libebl_%.map: libebl_%_pic.a $(libelf) $(libdw) +libebl_%.so libebl_%.map: libebl_%_pic.a $(libelf) $(libdw) $(libeu) @rm -f $(@:.so=.map) $(AM_V_at)echo 'ELFUTILS_$(PACKAGE_VERSION) { global: $*_init; local: *; };' \ > $(@:.so=.map) $(AM_V_CCLD)$(LINK) -shared -o $(@:.map=.so) \ -Wl,--whole-archive $< $(cpu_$*) -Wl,--no-whole-archive \ - -Wl,--version-script,$(@:.so=.map) \ - -Wl,-z,defs -Wl,--as-needed $(libelf) $(libdw) + -Wl,--version-script,$(@:.so=.map),--no-undefined \ + -Wl,-z,defs,-z,relro -Wl,--as-needed $(libelf) $(libdw) $(libeu) @$(textrel_check) libebl_i386.so: $(cpu_i386) diff --git a/libasm/Makefile.am b/libasm/Makefile.am index 8094b05..9effa6c 100644 --- a/libasm/Makefile.am +++ b/libasm/Makefile.am @@ -55,17 +55,19 @@ libasm_a_SOURCES = asm_begin.c asm_abort.c asm_end.c asm_error.c \ libasm_pic_a_SOURCES = am_libasm_pic_a_OBJECTS = $(libasm_a_SOURCES:.c=.os) -libasm_so_LDLIBS = +libasm_so_DEPS = ../lib/libeu.a ../libebl/libebl.a ../libelf/libelf.so ../libdw/libdw.so +libasm_so_LDLIBS = $(libasm_so_DEPS) if USE_LOCKS libasm_so_LDLIBS += -lpthread endif +libasm_so_LIBS = libasm_pic.a libasm_so_SOURCES = -libasm.so$(EXEEXT): libasm_pic.a libasm.map - $(AM_V_CCLD)$(LINK) -shared -o $@ -Wl,--whole-archive,$<,--no-whole-archive \ - -Wl,--version-script,$(srcdir)/libasm.map,--no-undefined \ - -Wl,--soname,$@.$(VERSION) \ - ../libebl/libebl.a ../libelf/libelf.so ../libdw/libdw.so \ +libasm.so$(EXEEXT): $(srcdir)/libasm.map $(libasm_so_LIBS) $(libasm_so_DEPS) + $(AM_V_CCLD)$(LINK) -shared -o $@ \ + -Wl,--soname,$@.$(VERSION),-z,defs,-z,relro \ + -Wl,--version-script,$<,--no-undefined \ + -Wl,--whole-archive $(libasm_so_LIBS) -Wl,--no-whole-archive \ $(libasm_so_LDLIBS) @$(textrel_check) $(AM_V_at)ln -fs $@ $@.$(VERSION) diff --git a/libdw/Makefile.am b/libdw/Makefile.am index 082d96c..634ac2e 100644 --- a/libdw/Makefile.am +++ b/libdw/Makefile.am @@ -102,17 +102,20 @@ endif libdw_pic_a_SOURCES = am_libdw_pic_a_OBJECTS = $(libdw_a_SOURCES:.c=.os) +libdw_so_LIBS = libdw_pic.a ../libdwelf/libdwelf_pic.a \ + ../libdwfl/libdwfl_pic.a ../libebl/libebl.a +libdw_so_DEPS = ../lib/libeu.a ../libelf/libelf.so +libdw_so_LDLIBS = $(libdw_so_DEPS) -ldl -lz $(argp_LDADD) $(zip_LIBS) libdw_so_SOURCES = -libdw.so$(EXEEXT): $(srcdir)/libdw.map libdw_pic.a ../libdwelf/libdwelf_pic.a \ - ../libdwfl/libdwfl_pic.a ../libebl/libebl.a \ - ../libelf/libelf.so +libdw.so$(EXEEXT): $(srcdir)/libdw.map $(libdw_so_LIBS) $(libdw_so_DEPS) # The rpath is necessary for libebl because its $ORIGIN use will # not fly in a setuid executable that links in libdw. - $(AM_V_CCLD)$(LINK) -shared -o $@ -Wl,--soname,$@.$(VERSION),-z,defs \ + $(AM_V_CCLD)$(LINK) -shared -o $@ \ + -Wl,--soname,$@.$(VERSION),-z,defs,-z,relro \ -Wl,--enable-new-dtags,-rpath,$(pkglibdir) \ -Wl,--version-script,$<,--no-undefined \ - -Wl,--whole-archive $(filter-out $<,$^) -Wl,--no-whole-archive\ - -ldl -lz $(argp_LDADD) $(zip_LIBS) + -Wl,--whole-archive $(libdw_so_LIBS) -Wl,--no-whole-archive \ + $(libdw_so_LDLIBS) @$(textrel_check) $(AM_V_at)ln -fs $@ $@.$(VERSION) diff --git a/libelf/Makefile.am b/libelf/Makefile.am index 167a832..88c1edd 100644 --- a/libelf/Makefile.am +++ b/libelf/Makefile.am @@ -95,16 +95,20 @@ libelf_a_SOURCES = elf_version.c elf_hash.c elf_error.c elf_fill.c \ libelf_pic_a_SOURCES = am_libelf_pic_a_OBJECTS = $(libelf_a_SOURCES:.c=.os) -libelf_so_LDLIBS = -lz +libelf_so_DEPS = ../lib/libeu.a +libelf_
[PATCH v2] Unify linking of libasm, libelf, libdw, backends
Link them all with -z,defs,-z,relro,--no-undefined, provide complete dependencies for the link steps, and add libeu.a to each one. libeu.a contains useful library functionality that each of them might use. The linker will strip unneeded symbols, so linking it in won't hurt even if none of the functions are used. Signed-off-by: Ulf Hermann --- backends/ChangeLog | 6 ++ backends/Makefile.am | 7 --- libasm/ChangeLog | 11 +++ libasm/Makefile.am | 14 -- libdw/ChangeLog | 9 + libdw/Makefile.am| 15 +-- libelf/ChangeLog | 8 libelf/Makefile.am | 14 +- 8 files changed, 64 insertions(+), 20 deletions(-) diff --git a/backends/ChangeLog b/backends/ChangeLog index 02efb00..e66a5e0 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,9 @@ +2017-02-17 Ulf Hermann + + * Makefile.am: Add libeu. + (libebl_%so): Link with --no-undefined,-z,defs,-z,relro + and libeu.a. + 2017-02-09 Ulf Hermann * aarch64_unwind.c: New file diff --git a/backends/Makefile.am b/backends/Makefile.am index bfb6b84..79bd26c 100644 --- a/backends/Makefile.am +++ b/backends/Makefile.am @@ -45,6 +45,7 @@ noinst_DATA = $(libebl_pic:_pic.a=.so) libelf = ../libelf/libelf.so libdw = ../libdw/libdw.so +libeu = ../lib/libeu.a i386_SRCS = i386_init.c i386_symbol.c i386_corenote.c i386_cfi.c \ i386_retval.c i386_regs.c i386_auxv.c i386_syscall.c \ @@ -130,14 +131,14 @@ libebl_bpf_pic_a_SOURCES = $(bpf_SRCS) am_libebl_bpf_pic_a_OBJECTS = $(bpf_SRCS:.c=.os) -libebl_%.so libebl_%.map: libebl_%_pic.a $(libelf) $(libdw) +libebl_%.so libebl_%.map: libebl_%_pic.a $(libelf) $(libdw) $(libeu) @rm -f $(@:.so=.map) $(AM_V_at)echo 'ELFUTILS_$(PACKAGE_VERSION) { global: $*_init; local: *; };' \ > $(@:.so=.map) $(AM_V_CCLD)$(LINK) -shared -o $(@:.map=.so) \ -Wl,--whole-archive $< $(cpu_$*) -Wl,--no-whole-archive \ - -Wl,--version-script,$(@:.so=.map) \ - -Wl,-z,defs -Wl,--as-needed $(libelf) $(libdw) + -Wl,--version-script,$(@:.so=.map),--no-undefined \ + -Wl,-z,defs,-z,relro -Wl,--as-needed $(libelf) $(libdw) $(libeu) @$(textrel_check) libebl_i386.so: $(cpu_i386) diff --git a/libasm/ChangeLog b/libasm/ChangeLog index 26fc5a9..57b9ce1 100644 --- a/libasm/ChangeLog +++ b/libasm/ChangeLog @@ -1,3 +1,14 @@ +2017-02-17 Ulf Hermann + + * Makefile.am: Add libasm_so_DEPS to specify external libraries + that have to be linked in, and libasm_so_LIBS to specify the + archives libasm consists of. The dependencies include libeu.a. + (libasm_so_LDLIBS): Add $(libasm_so_DEPS). + (libasm_so$(EXEEXT): Use $(libasm_so_LIBS), + add --no-undefined,-z,defs,-z,relro, + drop the manual enumeration of dependencies, + specify the correct path for libasm.map. + 2017-02-15 Ulf Hermann * disasm_str.c: Include system.h. diff --git a/libasm/Makefile.am b/libasm/Makefile.am index 8094b05..9effa6c 100644 --- a/libasm/Makefile.am +++ b/libasm/Makefile.am @@ -55,17 +55,19 @@ libasm_a_SOURCES = asm_begin.c asm_abort.c asm_end.c asm_error.c \ libasm_pic_a_SOURCES = am_libasm_pic_a_OBJECTS = $(libasm_a_SOURCES:.c=.os) -libasm_so_LDLIBS = +libasm_so_DEPS = ../lib/libeu.a ../libebl/libebl.a ../libelf/libelf.so ../libdw/libdw.so +libasm_so_LDLIBS = $(libasm_so_DEPS) if USE_LOCKS libasm_so_LDLIBS += -lpthread endif +libasm_so_LIBS = libasm_pic.a libasm_so_SOURCES = -libasm.so$(EXEEXT): libasm_pic.a libasm.map - $(AM_V_CCLD)$(LINK) -shared -o $@ -Wl,--whole-archive,$<,--no-whole-archive \ - -Wl,--version-script,$(srcdir)/libasm.map,--no-undefined \ - -Wl,--soname,$@.$(VERSION) \ - ../libebl/libebl.a ../libelf/libelf.so ../libdw/libdw.so \ +libasm.so$(EXEEXT): $(srcdir)/libasm.map $(libasm_so_LIBS) $(libasm_so_DEPS) + $(AM_V_CCLD)$(LINK) -shared -o $@ \ + -Wl,--soname,$@.$(VERSION),-z,defs,-z,relro \ + -Wl,--version-script,$<,--no-undefined \ + -Wl,--whole-archive $(libasm_so_LIBS) -Wl,--no-whole-archive \ $(libasm_so_LDLIBS) @$(textrel_check) $(AM_V_at)ln -fs $@ $@.$(VERSION) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 978b991..0cc6049 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,12 @@ +2017-02-17 Ulf Hermann + + * Makefile.am: Add libdw_so_LIBS to specify the archives libdw is is + made of, libdw_so_DEPS for libraries it depends on (including + libeu.a), libdw_so_LDLIBS to specify libraries libdw links against. + (libdw.so$(EXEEXT)): Add $(libdw_so_LDLIBS), remove enumeration of + library dependencies, use libdw_so_LIBS rather than relying on the + order of dependencies specified, add -z,relro. + 2016-10-22 Mark Wielaard
[PATCH] Make the replacement mempcpy a function
This way we don't have to evaluate the 'n' argument twice. We now need to link libeu.a into some tests, though. The system.h include was accidentally dropped from elfcompress.c and findtextrel.c, but is actually necessary when mempcpy is only available from libeu. Signed-off-by: Ulf Hermann --- ChangeLog | 4 configure.ac | 1 + lib/ChangeLog | 7 +++ lib/Makefile.am | 4 lib/mempcpy.c | 41 + lib/system.h | 3 +-- src/ChangeLog | 5 + src/elfcompress.c | 1 + src/findtextrel.c | 2 +- tests/ChangeLog | 4 tests/Makefile.am | 20 ++-- 11 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 lib/mempcpy.c diff --git a/ChangeLog b/ChangeLog index 48185c3..15b36dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-02-17 Ulf Hermann + + * configure.ac: Define HAVE_MEMPCPY if mempcpy is available. + 2017-02-15 Ulf Hermann * configure.ac: Add check for mempcpy. diff --git a/configure.ac b/configure.ac index 3c35dac..303bf4d 100644 --- a/configure.ac +++ b/configure.ac @@ -288,6 +288,7 @@ AC_CHECK_DECLS([powerof2],[],[],[#include ]) AC_CHECK_DECLS([mempcpy],[],[], [#define _GNU_SOURCE #include ]) +AM_CONDITIONAL(HAVE_MEMPCPY, [test "x$ac_cv_have_decl_mempcpy" = "xyes"]) AC_CHECK_LIB([stdc++], [__cxa_demangle], [dnl AC_DEFINE([USE_DEMANGLE], [1], [Defined if demangling is enabled])]) diff --git a/lib/ChangeLog b/lib/ChangeLog index 84290f7..dcd20e1 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,10 @@ +2017-02-17 Ulf Hermann + + * system.h: Make mempcpy a function. + * mempcpy.c: New file. + * Makefile.am (libeu_a_SOURCES): Add mempcpy.c if mempcpy is not + available from libc. + 2017-02-16 Ulf Hermann * Makefile.am (libeu_a_SOURCES): Remove version.c, add printversion.c diff --git a/lib/Makefile.am b/lib/Makefile.am index 7a65eb9..63738fd 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -41,6 +41,10 @@ noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \ md5.h sha1.h eu-config.h color.h printversion.h EXTRA_DIST = dynamicsizehash.c +if !HAVE_MEMPCPY +libeu_a_SOURCES += mempcpy.c +endif + if !GPROF xmalloc_CFLAGS = -ffunction-sections endif diff --git a/lib/mempcpy.c b/lib/mempcpy.c new file mode 100644 index 000..aff8d54 --- /dev/null +++ b/lib/mempcpy.c @@ -0,0 +1,41 @@ +/* Implementation of mempcpy, using memcpy + Copyright (C) 2017 The Qt Company Ltd. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + elfutils 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 copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "system.h" +#include + +void * +mempcpy(void *dest, const void *src, size_t n) +{ +return (char *) memcpy (dest, src, n) + n; +} + diff --git a/lib/system.h b/lib/system.h index 2d05702..6ddbb2d 100644 --- a/lib/system.h +++ b/lib/system.h @@ -68,8 +68,7 @@ #endif #if !HAVE_DECL_MEMPCPY -#define mempcpy(dest, src, n) \ -((void *) ((char *) memcpy (dest, src, n) + (size_t) n)) +void *mempcpy(void *dest, const void *src, size_t n); #endif /* A special gettext function we use if the strings are too short. */ diff --git a/src/ChangeLog b/src/ChangeLog index 0601198..d26169b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2017-02-17 Ulf Hermann + + * elfcompress.c: Include system.h. + * findtextrel.c: Likewise. + 2017-02-16 Ulf Hermann * addr2line.c: Include printversion.h diff --git a/src/elfcompress.c b/src/elfcompress.c index 8e0d5c5..cf85820 100644 --- a/src/elfcompress.c +++ b/src/elfcompress.c @@ -36,6 +36,7 @@ #include #include "libeu.h" #include "printversion.h" +#include "system.h" /* Name and version of program. */ ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; diff --git a/src/findtextrel.c b/src/findtextrel.c index 8f1e239..5382abd 100644 --- a/src/findtextrel.c +++ b/s
[PATCH 1/2] Allow building the libraries without argp
If argp is unavailable we cannot build tests, tools and argp-std.c in libdwfl. We can still build the libraries, though. Test for this and provide a dwfl_standard_argp() that just returns NULL and only gets compiled if argp is missing. Signed-off-by: Ulf Hermann --- ChangeLog| 12 Makefile.am | 6 +- configure.ac | 31 +-- lib/ChangeLog| 7 +++ lib/Makefile.am | 10 +++--- libdwfl/ChangeLog| 6 ++ libdwfl/Makefile.am | 8 +++- libdwfl/argp-dummy.c | 38 ++ 8 files changed, 103 insertions(+), 15 deletions(-) create mode 100644 libdwfl/argp-dummy.c diff --git a/ChangeLog b/ChangeLog index 15b36dd..e93d05f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2017-02-20 Ulf Hermann + + * configure.ac: Don't abort if no argp is found. Only print a + warning, rename have_argp to with_argp (like lzma, bzip2 ..), + and use "yes"/"no" as values, as we do for other variables. + * configure.ac: Set with_argp also if argp is in libargp, and + pass it on as AM_CONDITIONAL ARGP. + * configure.ac: Skip configuration of src and tests if + argp is not available. + * Makefile.am (SUBDIRS): Skip src and tests if argp is not + available. + 2017-02-17 Ulf Hermann * configure.ac: Define HAVE_MEMPCPY if mempcpy is available. diff --git a/Makefile.am b/Makefile.am index 2ff444e..59225cc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -28,7 +28,11 @@ pkginclude_HEADERS = version.h # Add doc back when we have some real content. SUBDIRS = config m4 lib libelf libebl libdwelf libdwfl libdw libcpu libasm \ - backends src po tests + backends po + +if ARGP +SUBDIRS += src tests +endif EXTRA_DIST = elfutils.spec GPG-KEY NOTES CONTRIBUTING \ COPYING COPYING-GPLV2 COPYING-LGPLV3 diff --git a/configure.ac b/configure.ac index 303bf4d..60b8796 100644 --- a/configure.ac +++ b/configure.ac @@ -367,24 +367,27 @@ AC_LINK_IFELSE( [#include ], [int argc=1; char *argv[]={"test"}; argp_parse(0,argc,&argv,0,0,0); return 0;] )], - [libc_has_argp="true"], - [libc_has_argp="false"] + [libc_has_argp="yes"], + [libc_has_argp="no"] ) dnl If our libc doesn't provide argp, then test for libargp -if test "$libc_has_argp" = "false" ; then +if test "$libc_has_argp" = "no" ; then AC_MSG_WARN("libc does not have argp") - AC_CHECK_LIB([argp], [argp_parse], [have_argp="true"], [have_argp="false"]) + AC_CHECK_LIB([argp], [argp_parse], [with_argp="yes"], [with_argp="no"]) - if test "$have_argp" = "false"; then - AC_MSG_ERROR("no libargp found") + if test "$with_argp" = "no"; then + AC_MSG_WARN("no libargp found") + argp_LDADD="" else argp_LDADD="-largp" fi else + with_argp="yes" argp_LDADD="" fi AC_SUBST([argp_LDADD]) +AM_CONDITIONAL(ARGP, [test "x$with_argp" = "xyes"]) dnl Check if we have for EM_BPF disassembly. AC_CHECK_HEADERS(linux/bpf.h) @@ -424,12 +427,19 @@ AC_CONFIG_FILES([libasm/Makefile]) dnl CPU-specific backend libraries. AC_CONFIG_FILES([backends/Makefile]) -dnl Tools. -AC_CONFIG_FILES([src/Makefile po/Makefile.in]) +dnl Translations +AC_CONFIG_FILES([po/Makefile.in]) -dnl Test suite. AM_CONDITIONAL(STANDALONE, false)dnl Used in tests/Makefile.am, which see. -AC_CONFIG_FILES([tests/Makefile]) +if test "x$with_argp" = "xyes"; then + dnl Tools. + AC_CONFIG_FILES([src/Makefile]) + + dnl Test suite. + AC_CONFIG_FILES([tests/Makefile]) +else + AC_MSG_WARN("Not building tools or tests.") +fi dnl pkgconfig files AC_CONFIG_FILES([config/libelf.pc config/libdw.pc]) @@ -546,6 +556,7 @@ AC_MSG_NOTICE([ build arch : ${ac_cv_build} RECOMMENDED FEATURES (should all be yes) +argp support : ${with_argp} gzip support : ${with_zlib} bzip2 support : ${with_bzlib} lzma/xz support: ${with_lzma} diff --git a/lib/ChangeLog b/lib/ChangeLog index dcd20e1..c97537e 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,10 @@ +2017-02-20 Ulf Hermann + + * Makefile.am (libeu_a_SOURCES): Skip printversion.c and + color.c if argp is not available. + (noinst_HEADERS): Skip printversion.h and color.h if argp is + not available. + 2017-02-17 Ulf Hermann * system.h: Make mempcpy a function
[PATCH 2/2] Output information about buildable components
If argp is missing we build without tools and tests. We might also make libasm optional in the future, as it is only used in maintainer mode. A libelf-only build without libdw and the ebl backends is also feasible. The user should be notified about what is actually buildable with a given configuration. Signed-off-by: Ulf Hermann --- ChangeLog| 5 + configure.ac | 16 +++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e93d05f..e97e02b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2017-02-20 Ulf Hermann + * configure.ac: Track which components are enabled and output + a summary in the end. + +2017-02-20 Ulf Hermann + * configure.ac: Don't abort if no argp is found. Only print a warning, rename have_argp to with_argp (like lzma, bzip2 ..), and use "yes"/"no" as values, as we do for other variables. diff --git a/configure.ac b/configure.ac index 60b8796..ed60be5 100644 --- a/configure.ac +++ b/configure.ac @@ -403,6 +403,7 @@ dnl Support library. AC_CONFIG_FILES([lib/Makefile]) dnl ELF library. +enable_libelf="yes" AC_CONFIG_FILES([libelf/Makefile]) dnl Higher-level ELF support library. @@ -412,6 +413,7 @@ dnl DWARF-ELF Lower-level Functions support library. AC_CONFIG_FILES([libdwelf/Makefile]) dnl DWARF library. +enable_libdw="yes" AC_CONFIG_FILES([libdw/Makefile]) dnl Higher-level DWARF support library. @@ -421,7 +423,8 @@ dnl CPU handling library. AC_CONFIG_FILES([libcpu/Makefile]) dnl Assembler library. -AM_CONDITIONAL(HAVE_LIBASM, true)dnl Used in tests/Makefile.am, which see. +enable_libasm="yes" +AM_CONDITIONAL(HAVE_LIBASM, test "x$enable_libasm" = "xyes")dnl Used in tests/Makefile.am, which see. AC_CONFIG_FILES([libasm/Makefile]) dnl CPU-specific backend libraries. @@ -433,11 +436,15 @@ AC_CONFIG_FILES([po/Makefile.in]) AM_CONDITIONAL(STANDALONE, false)dnl Used in tests/Makefile.am, which see. if test "x$with_argp" = "xyes"; then dnl Tools. + enable_tools="yes" AC_CONFIG_FILES([src/Makefile]) dnl Test suite. + enable_tests="yes" AC_CONFIG_FILES([tests/Makefile]) else + enable_tools="no" + enable_tests="no" AC_MSG_WARN("Not building tools or tests.") fi @@ -580,4 +587,11 @@ AC_MSG_NOTICE([ gcc undefined behaviour sanitizer : ${use_undefined} use rpath in tests : ${tests_use_rpath} test biarch: ${utrace_cv_cc_biarch} + + BUILDABLE COMPONENTS +libasm : ${enable_libasm} +libelf : ${enable_libelf} +libdw and ebl backends : ${enable_libdw} +tools : ${enable_tools} +tests : ${enable_tests} ]) -- 2.1.4
[PATCH] Check for existence of asprintf and vasprintf
Add replacements to libeu.a if they don't exist. Include system.h and link against libeu.a where they are used. Signed-off-by: Ulf Hermann --- ChangeLog | 4 configure.ac | 10 ++ lib/ChangeLog | 10 ++ lib/Makefile.am| 8 lib/asprintf.c | 46 ++ lib/color.c| 1 + lib/system.h | 9 + lib/vasprintf.c| 49 + libdwfl/ChangeLog | 4 libdwfl/offline.c | 1 + src/ChangeLog | 5 + src/arlib-argp.c | 1 + src/unstrip.c | 1 + tests/ChangeLog| 7 +++ tests/Makefile.am | 4 ++-- tests/backtrace-data.c | 2 ++ tests/backtrace.c | 2 ++ 17 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 lib/asprintf.c create mode 100644 lib/vasprintf.c diff --git a/ChangeLog b/ChangeLog index e97e02b..8e01ce2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-02-22 Ulf Hermann + + * configure.ac: Add checks for asprintf and vasprintf. + 2017-02-20 Ulf Hermann * configure.ac: Track which components are enabled and output diff --git a/configure.ac b/configure.ac index ed60be5..3d4bb70 100644 --- a/configure.ac +++ b/configure.ac @@ -290,6 +290,16 @@ AC_CHECK_DECLS([mempcpy],[],[], #include ]) AM_CONDITIONAL(HAVE_MEMPCPY, [test "x$ac_cv_have_decl_mempcpy" = "xyes"]) +AC_CHECK_DECLS([asprintf],[],[], + [#define _GNU_SOURCE +#include ]) +AM_CONDITIONAL(HAVE_ASPRINTF, [test "x$ac_cv_have_decl_asprintf" = "xyes"]) + +AC_CHECK_DECLS([vasprintf],[],[], + [#define _GNU_SOURCE +#include ]) +AM_CONDITIONAL(HAVE_VASPRINTF, [test "x$ac_cv_have_decl_vasprintf" = "xyes"]) + AC_CHECK_LIB([stdc++], [__cxa_demangle], [dnl AC_DEFINE([USE_DEMANGLE], [1], [Defined if demangling is enabled])]) AM_CONDITIONAL(DEMANGLE, test "x$ac_cv_lib_stdcpp___cxa_demangle" = "xyes") diff --git a/lib/ChangeLog b/lib/ChangeLog index c97537e..d0229ec 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,13 @@ +2017-02-22 Ulf Hermann + + * Makefile.am (libeu_a_SOURCES): Add asprintf.c and vasprintf.c + if !HAVE_ASPRINTF and !HAVE_VASPRINTF, respectively. + * asprintf.c: New file. + * vasprintf.c: New file. + * color.c: Include system.h. + * system.h: Include stdarg.h, add declarations for asprintf and + vasprintf if they are not available from libc. + 2017-02-20 Ulf Hermann * Makefile.am (libeu_a_SOURCES): Skip printversion.c and diff --git a/lib/Makefile.am b/lib/Makefile.am index 93a965c..02e6bd9 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -44,6 +44,14 @@ if !HAVE_MEMPCPY libeu_a_SOURCES += mempcpy.c endif +if !HAVE_ASPRINTF +libeu_a_SOURCES += asprintf.c +endif + +if !HAVE_VASPRINTF +libeu_a_SOURCES += vasprintf.c +endif + if ARGP libeu_a_SOURCES += printversion.c color.c noinst_HEADERS += printversion.h color.h diff --git a/lib/asprintf.c b/lib/asprintf.c new file mode 100644 index 000..4e10f5c --- /dev/null +++ b/lib/asprintf.c @@ -0,0 +1,46 @@ +/* Implementation of asprintf, using vasprintf + Copyright (C) 2017 The Qt Company Ltd. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + elfutils 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 copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "system.h" +#include +#include +#include + +int +asprintf(char **strp, const char *fmt, ...) +{ +va_list ap; +va_start(ap, fmt); +int result = vasprintf(strp, fmt, ap); +va_end(ap); +return result; +} diff --git a/lib/color.c b/lib/color.c index f62389d..3362f83 100644 --- a/lib/color.c +++ b/lib/color.c @@ -39,6 +39,7 @@ #include #include "libeu.h" #include "color.h" +#include "system.h" /* Prototype for option handler. */ static error_t parse_opt (int k
[PATCH] Check for existence of GNU-style basename()
If it doesn't exist, add an implementation to libeu.a. Include system.h and link against libeu.a where it is used. Signed-off-by: Ulf Hermann --- ChangeLog | 4 configure.ac | 5 + lib/ChangeLog | 7 +++ lib/Makefile.am | 4 lib/basename.c| 41 +++ lib/system.h | 4 libdw/ChangeLog | 4 libdw/dwarf_getsrc_file.c | 2 ++ libdwfl/ChangeLog | 4 libdwfl/dwfl_module_getsrc_file.c | 2 +- tests/ChangeLog | 7 +++ tests/Makefile.am | 4 ++-- tests/show-die-info.c | 1 + tests/varlocs.c | 1 + 14 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 lib/basename.c diff --git a/ChangeLog b/ChangeLog index 8e01ce2..d1e36f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2017-02-22 Ulf Hermann + * configure.ac: Add check GNU-style basename. + +2017-02-22 Ulf Hermann + * configure.ac: Add checks for asprintf and vasprintf. 2017-02-20 Ulf Hermann diff --git a/configure.ac b/configure.ac index 3d4bb70..889f88c 100644 --- a/configure.ac +++ b/configure.ac @@ -300,6 +300,11 @@ AC_CHECK_DECLS([vasprintf],[],[], #include ]) AM_CONDITIONAL(HAVE_VASPRINTF, [test "x$ac_cv_have_decl_vasprintf" = "xyes"]) +AC_CHECK_DECLS([basename],[],[], + [#define _GNU_SOURCE +#include ]) +AM_CONDITIONAL(HAVE_BASENAME, [test "x$ac_cv_have_decl_basename" = "xyes"]) + AC_CHECK_LIB([stdc++], [__cxa_demangle], [dnl AC_DEFINE([USE_DEMANGLE], [1], [Defined if demangling is enabled])]) AM_CONDITIONAL(DEMANGLE, test "x$ac_cv_lib_stdcpp___cxa_demangle" = "xyes") diff --git a/lib/ChangeLog b/lib/ChangeLog index d0229ec..a8d9b91 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,5 +1,12 @@ 2017-02-22 Ulf Hermann + * Makefile.am (libeu_a_SOURCES): Add basname.c if no GNU-style + basename is available. + * basename.c: New file. + * system.h: Add declaration of basename if !HAVE_DECL_BASENAME. + +2017-02-22 Ulf Hermann + * Makefile.am (libeu_a_SOURCES): Add asprintf.c and vasprintf.c if !HAVE_ASPRINTF and !HAVE_VASPRINTF, respectively. * asprintf.c: New file. diff --git a/lib/Makefile.am b/lib/Makefile.am index 02e6bd9..0f3bfe7 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -57,6 +57,10 @@ libeu_a_SOURCES += printversion.c color.c noinst_HEADERS += printversion.h color.h endif +if !HAVE_BASENAME +libeu_a_SOURCES += basename.c +endif + if !GPROF xmalloc_CFLAGS = -ffunction-sections endif diff --git a/lib/basename.c b/lib/basename.c new file mode 100644 index 000..a104db6 --- /dev/null +++ b/lib/basename.c @@ -0,0 +1,41 @@ +/* Implementation of GNU-style basename() + Copyright (C) 2017 The Qt Company Ltd. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + elfutils 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 copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "system.h" +#include + +char * +basename (const char *path) +{ + char *base = strrchr(path, '/'); + return base ? base + 1 : (char *)path; +} diff --git a/lib/system.h b/lib/system.h index b6f2269..7539e11 100644 --- a/lib/system.h +++ b/lib/system.h @@ -80,6 +80,10 @@ int asprintf (char **strp, const char *fmt, ...); int vasprintf (char **strp, const char *fmt, va_list ap); #endif +#if !HAVE_DECL_BASENAME +char *basename (const char *path); +#endif + /* A special gettext function we use if the strings are too short. */ #define sgettext(Str) \ ({ const char *__res = strrchr (gettext (Str), '|'); \ diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 0cc6049..694b7ce 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,7 @@ +2017-02-22 Ulf Hermann + + * dwarf_getsrc_file.c: Include system.h.
[PATCH] Define fputs_unlocked to fputs if it is not available
Using fputs_unlocked over fputs is a nice optimization, but ultimately the result is the same. So, if we don't have fputs_unlocked we can just use fputs instead. Signed-off-by: Ulf Hermann --- ChangeLog | 4 configure.ac | 4 lib/ChangeLog | 5 + lib/system.h | 4 4 files changed, 17 insertions(+) diff --git a/ChangeLog b/ChangeLog index d1e36f6..dd9b9ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2017-02-22 Ulf Hermann + * configure.ac: Add check for fputs_unlocked. + +2017-02-22 Ulf Hermann + * configure.ac: Add check GNU-style basename. 2017-02-22 Ulf Hermann diff --git a/configure.ac b/configure.ac index 889f88c..8119e07 100644 --- a/configure.ac +++ b/configure.ac @@ -305,6 +305,10 @@ AC_CHECK_DECLS([basename],[],[], #include ]) AM_CONDITIONAL(HAVE_BASENAME, [test "x$ac_cv_have_decl_basename" = "xyes"]) +AC_CHECK_DECLS([fputs_unlocked],[],[], + [#define _GNU_SOURCE +#include ]) + AC_CHECK_LIB([stdc++], [__cxa_demangle], [dnl AC_DEFINE([USE_DEMANGLE], [1], [Defined if demangling is enabled])]) AM_CONDITIONAL(DEMANGLE, test "x$ac_cv_lib_stdcpp___cxa_demangle" = "xyes") diff --git a/lib/ChangeLog b/lib/ChangeLog index a8d9b91..d9aabfa 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,5 +1,10 @@ 2017-02-22 Ulf Hermann + * system.h: Define fputs_unlocked to fputs if + !HAVE_DECL_FPUTS_UNLOCKED. + +2017-02-22 Ulf Hermann + * Makefile.am (libeu_a_SOURCES): Add basname.c if no GNU-style basename is available. * basename.c: New file. diff --git a/lib/system.h b/lib/system.h index 7539e11..dc78997 100644 --- a/lib/system.h +++ b/lib/system.h @@ -84,6 +84,10 @@ int vasprintf (char **strp, const char *fmt, va_list ap); char *basename (const char *path); #endif +#if !HAVE_DECL_FPUTS_UNLOCKED +#define fputs_unlocked(str, stream) fputs (str, stream) +#endif + /* A special gettext function we use if the strings are too short. */ #define sgettext(Str) \ ({ const char *__res = strrchr (gettext (Str), '|'); \ -- 2.1.4
[PATCH] Check for existence of GNU-style strerror_r
If we don't have it, we don't translate system error codes to strings in dwfl_error.c. Signed-off-by: Ulf Hermann --- ChangeLog| 4 configure.ac | 2 ++ libdwfl/ChangeLog| 5 + libdwfl/dwfl_error.c | 4 4 files changed, 15 insertions(+) diff --git a/ChangeLog b/ChangeLog index dd9b9ac..1acc8ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2017-02-22 Ulf Hermann + * configure.ac: Check for strerror_r and its variants. + +2017-02-22 Ulf Hermann + * configure.ac: Add check for fputs_unlocked. 2017-02-22 Ulf Hermann diff --git a/configure.ac b/configure.ac index 8119e07..ce40539 100644 --- a/configure.ac +++ b/configure.ac @@ -309,6 +309,8 @@ AC_CHECK_DECLS([fputs_unlocked],[],[], [#define _GNU_SOURCE #include ]) +AC_FUNC_STRERROR_R + AC_CHECK_LIB([stdc++], [__cxa_demangle], [dnl AC_DEFINE([USE_DEMANGLE], [1], [Defined if demangling is enabled])]) AM_CONDITIONAL(DEMANGLE, test "x$ac_cv_lib_stdcpp___cxa_demangle" = "xyes") diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index f5921dc..1a23136 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,5 +1,10 @@ 2017-02-22 Ulf Hermann + * dwfl_error.c: If we don't have a strerror_r returning a char*, + output a less useful message in case of a system error. + +2017-02-22 Ulf Hermann + * dwfl_module_getsrc_file.c: Include system.h. 2017-02-22 Ulf Hermann diff --git a/libdwfl/dwfl_error.c b/libdwfl/dwfl_error.c index 7bcf61c..7733496 100644 --- a/libdwfl/dwfl_error.c +++ b/libdwfl/dwfl_error.c @@ -154,7 +154,11 @@ dwfl_errmsg (int error) switch (error &~ 0x) { case OTHER_ERROR (ERRNO): +#ifdef STRERROR_R_CHAR_P return strerror_r (error & 0x, "bad", 0); +#else + return "Unkown error. See errno"; +#endif case OTHER_ERROR (LIBELF): return elf_errmsg (error & 0x); case OTHER_ERROR (LIBDW): -- 2.1.4
[PATCH] Check for program_invocation_short_name
If it doesn't exist use "" as generic replacement. Signed-off-by: Ulf Hermann --- ChangeLog | 4 configure.ac | 5 + lib/ChangeLog | 5 + lib/system.h | 4 src/ChangeLog | 4 src/elfcmp.c | 1 + 6 files changed, 23 insertions(+) diff --git a/ChangeLog b/ChangeLog index 1acc8ba..31285e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2017-02-22 Ulf Hermann + * configure.ac: Add check for program_invocation_short_name. + +2017-02-22 Ulf Hermann + * configure.ac: Check for strerror_r and its variants. 2017-02-22 Ulf Hermann diff --git a/configure.ac b/configure.ac index ce40539..9a9404b 100644 --- a/configure.ac +++ b/configure.ac @@ -309,6 +309,10 @@ AC_CHECK_DECLS([fputs_unlocked],[],[], [#define _GNU_SOURCE #include ]) +AC_CHECK_DECLS([program_invocation_short_name],[],[], + [#define _GNU_SOURCE +#include ]) + AC_FUNC_STRERROR_R AC_CHECK_LIB([stdc++], [__cxa_demangle], [dnl @@ -407,6 +411,7 @@ else with_argp="yes" argp_LDADD="" fi + AC_SUBST([argp_LDADD]) AM_CONDITIONAL(ARGP, [test "x$with_argp" = "xyes"]) diff --git a/lib/ChangeLog b/lib/ChangeLog index d9aabfa..847ca87 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,5 +1,10 @@ 2017-02-22 Ulf Hermann + * system.h: Define program_invocation_short_name to "" if + !HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME. + +2017-02-22 Ulf Hermann + * system.h: Define fputs_unlocked to fputs if !HAVE_DECL_FPUTS_UNLOCKED. diff --git a/lib/system.h b/lib/system.h index dc78997..f71e85c 100644 --- a/lib/system.h +++ b/lib/system.h @@ -88,6 +88,10 @@ char *basename (const char *path); #define fputs_unlocked(str, stream) fputs (str, stream) #endif +#if !HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME +#define program_invocation_short_name "" +#endif + /* A special gettext function we use if the strings are too short. */ #define sgettext(Str) \ ({ const char *__res = strrchr (gettext (Str), '|'); \ diff --git a/src/ChangeLog b/src/ChangeLog index bdf04cc..29aa8eb 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,9 @@ 2017-02-22 Ulf Hermann + * elfcmp.c: Include system.h. + +2017-02-22 Ulf Hermann + * arlib-argp.c: Include system.h. * unstrip.c: Likewise. diff --git a/src/elfcmp.c b/src/elfcmp.c index 7673cf2..ea34527 100644 --- a/src/elfcmp.c +++ b/src/elfcmp.c @@ -34,6 +34,7 @@ #include #include +#include #include "../libelf/elf-knowledge.h" #include "../libebl/libeblP.h" -- 2.1.4
Re: [PATCH] Check for existence of asprintf and vasprintf
> these portability replacements are starting to get out of hand > -mike To what extent should elfutils be portable to non-GNU systems? My goal here is to port it to windows while minimizing the amount of external dependencies I have to add. The functions I have replaced so far are so trivial that I didn't consider it worthwhile to import things from gnulib in order to provide them. Ulf
[PATCH v2] Check for existence of GNU-style strerror_r
If we don't have it, we don't translate system error codes to strings in dwfl_error.c. Signed-off-by: Ulf Hermann --- ChangeLog| 4 configure.ac | 2 ++ libdwfl/ChangeLog| 5 + libdwfl/dwfl_error.c | 4 4 files changed, 15 insertions(+) diff --git a/ChangeLog b/ChangeLog index dd9b9ac..1acc8ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2017-02-22 Ulf Hermann + * configure.ac: Check for strerror_r and its variants. + +2017-02-22 Ulf Hermann + * configure.ac: Add check for fputs_unlocked. 2017-02-22 Ulf Hermann diff --git a/configure.ac b/configure.ac index 8119e07..ce40539 100644 --- a/configure.ac +++ b/configure.ac @@ -309,6 +309,8 @@ AC_CHECK_DECLS([fputs_unlocked],[],[], [#define _GNU_SOURCE #include ]) +AC_FUNC_STRERROR_R + AC_CHECK_LIB([stdc++], [__cxa_demangle], [dnl AC_DEFINE([USE_DEMANGLE], [1], [Defined if demangling is enabled])]) AM_CONDITIONAL(DEMANGLE, test "x$ac_cv_lib_stdcpp___cxa_demangle" = "xyes") diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index f5921dc..1a23136 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,5 +1,10 @@ 2017-02-22 Ulf Hermann + * dwfl_error.c: If we don't have a strerror_r returning a char*, + output a less useful message in case of a system error. + +2017-02-22 Ulf Hermann + * dwfl_module_getsrc_file.c: Include system.h. 2017-02-22 Ulf Hermann diff --git a/libdwfl/dwfl_error.c b/libdwfl/dwfl_error.c index 7bcf61c..aba3cca 100644 --- a/libdwfl/dwfl_error.c +++ b/libdwfl/dwfl_error.c @@ -154,7 +154,11 @@ dwfl_errmsg (int error) switch (error &~ 0x) { case OTHER_ERROR (ERRNO): +#ifdef STRERROR_R_CHAR_P return strerror_r (error & 0x, "bad", 0); +#else + return "Unknown error. See errno"; +#endif case OTHER_ERROR (LIBELF): return elf_errmsg (error & 0x); case OTHER_ERROR (LIBDW): -- 2.1.4
Re: [PATCH] Check for existence of asprintf and vasprintf
> imo, elfutils shouldn't be growing these fallback implementations itself. > if you want to do this stuff, use gnulib instead. > > then there is no ifdef hell in the source files, and you don't have to > worry about testing whether the ifdef's are correct because gnulib did > it all for you. OK, so I won't post any more patches with replacement functions. I don't like the idea of using gnulib because the gnulib implementations are generally more complex and in order to maintain them I would have to track gnulib in addition to elfutils. Also I would have to review the licenses for each import. This is not something I'm excited to do for a few 3-line functions. But OK, I will consider it. What about switching off functionality if certain conditions aren't met? For example the patch that allows us to build libelf and libdw if argp is not available. Are such changes acceptable? I have something similar for obstack, and possibly for fts. Ulf
Re: [PATCH] Check for existence of asprintf and vasprintf
> sorry, but i don't know what you're talking about. you don't read the > gnulib code/modules directly, you just run gnulib-tool and tell it which > modules to import. it does all the rest for you. > > you want asprintf ? then add it to the list. > modules=( > asprintf > glob > vasprintf > ...whatever else you want... > ) > gnulib-tool --import "${modules[@]}" I see. Some of the functions are not available from gnulib, though. In particular, GNU-style basename abd GNU-style strerror_r. There might be more. Ulf
Re: [PATCH] Check for existence of asprintf and vasprintf
> basename() is in the dirname module That's the POSIX variant. We're using the GNU variant everywhere and the GNU variant is a whopping two lines of code: char *base = strrchr(path, '/'); return base ? base + 1 : (char *)path; > you're correct that GNU strerror_r is not handled by gnulib. > that doesn't look like it's too hard to deal with, but it is > something that'd have to be considered. We're using strerror_r in exactly one place and my proposal is to just return a fixed string if we hit that on platforms where GNU strerror_r is not available. Ulf
Re: [PATCH] Check for existence of asprintf and vasprintf
First, I'm not sure if we want to import the respective gnulib modules directly into the elfutils code base or if you want me to do this in my fork. In the latter case the issue is settled as there is no value for me in jumping through hoops if the code is not going to be upstreamed anyway. So, for now I'm assuming we're talking about importing gnulib modules into the elfutils code base. > gnulib-tool has a --lgpl=[...] flag so you can automatically abort if > the desired license compatibility level isn't met. so you don't have > to directly review every module if it isn't aborting. Are you aware that for most of those modules, building them into elfutils restricts the license choices for the resulting combination? Any non-trivial combination of the required modules with elfutils makes the result de facto GPLv3 only. GPLv3 is fine for me as perfparser is also GPLv3, but as elfutils so far is LGPLv3+/GPLv2+ I'm wondering if we want to do this. In fact, when just doing the usual "configure/make/make install" procedure without reviewing the intermediate results, a user would have no way of knowing what license applies to the binaries. IMO that is bad and will certainly lead to problems somewhere down the line. Ulf
Re: [PATCH] Check for existence of asprintf and vasprintf
Please compare the following code with asprintf.c/vasprintf.c/vasnprintf.c from gnulib. asprintf depends on vasprintf which in turn depends on vasnprintf there. vasnprintf is non-standard and not even available on glibc, while vsnprintf as used by my implementation is standardized by POSIX and widely available (even on windows). Granted, we have two calls to vsnprintf in my code vs one call to vasnprintf in the gnulib code. However, if that becomes an issue, I would rather go for some platform-specific optimization (windows also has a number of non-standard and possibly useful *printf functions) rather than importing such a monster. > +int > +asprintf(char **strp, const char *fmt, ...) > +{ > +va_list ap; > +va_start(ap, fmt); > +int result = vasprintf(strp, fmt, ap); > +va_end(ap); > +return result; > +} > + > +int > +vasprintf(char **strp, const char *fmt, va_list ap) > +{ > +va_list test; > +va_copy(test, ap); > +int length = vsnprintf(NULL, 0, fmt, test); > +va_end(test); > +*strp = malloc(length + 1); > +if (*strp == NULL) > +return -1; > +return vsnprintf(*strp, length + 1, fmt, ap); > +}
Re: [PATCH] Check for existence of asprintf and vasprintf
and the GNU variant is a whopping two lines of code: char *base = strrchr(path, '/'); return base ? base + 1 : (char *)path; and we get straight to an example of why your solutions don't scale. your replacement is wrong. and ironically, it's wrong on Windows, which is the whole point of your work. '/' is not the path sep used on every system out there. it also does not properly handle systems (such as Windows) that have filesystem prefixes like C:\. Both basename variants' documentations only talk about '/'. This is not the place where we should handle windows directory separators. We should either already expect forward slashes as input (with drive names as first path component, as e.g. msys does it), or convert them early on. And the implementation I've given above is the same code as in glibc. However, I will actually prepare some patches to replace missing functions using gnulib rather than my own implementations. Ulf
Re: frame unwinding patches
Ping? Any progress on merging this functionality upstream? It can make quite a difference in unwinding. The patches have also been in perfparser releases for over a year now. I would like to see them upstream. best, Ulf
Re: frame unwinding patches
- In the example above, the address points into libnvidia-glcore.so and as such not compiled by my colleague but rather provided by NVidia as a binary blob. When you only got a binary blob and have to make do with it, you cannot tell people to "just fix the compiler invocation". This is their problem they support a vendor who cripples usage of their products. There is also Intel and AMD. Sorry, but I cannot tell everybody with binary-only graphics drivers that they cannot use perfparser. That's probably the majority of embedded devices and a large number of desktops. - Some JIT compilers, like QV4, actually embed frame pointers into their dynamic code, but do not go the extra mile for generating DWARF data or asynchronous unwind tables. That is another case where the patches by Ulf excel and make elfutils much more useful. In such case elfutils could provide some workaround with a new eu-stack option: --please-workaround-a-completely-broken-compiler-i-still-have-not-fixed Frame pointers are the easiest way to include unwinding information into a binary and they require less work from the compiler than other methods. With JIT compilers, compile time matters much more than with ahead of time compilers. Also, adding extra code to the compiler has to be justified in that case as the compiler is shipped inside the libQt5Qml binary and loaded into memory whenever you run some QML. So, I think frame pointers are a perfectly valid option for unwinding and should be supported.
Re: dwfl_attach_state alternative taking Ebl?
> So you map from simple architecture name like "x86" or "powerpc". But > what mechanism do you have to whether that is 32 or 64 bit, and big or > little endian? The code can be extended to provide that information. We know it in advance, but didn't need it so far. Ulf
Re: frame unwinding patches
> I do agree with Jan that frame pointer unwinding is notoriously > untrustworthy. Even with some sanity checks it is hard to know whether > you are doing a correct unwind. gdb gets away with it through pretty > advanced frame sniffers, which take a lot of low-level compiler > generation knowledge to get correct (and even then...). You only restore > the pc, stack and frame pointer registers (maybe incorrectly). So > afterwards, even if you got valid CFI data you might be stuck. Yes, especially with mixed stack traces, where part of the stack has CFI and part of it doesn't, we quickly run into guesswork. I've regenerated the binaries as suggested, with the result being that raise() from libc actually has CFI, but doesn't set a frame pointer. So, the frame pointer unwinder can find raise() in the link register, but it sets up the FP register with the wrong value. Then raise() is unwound using CFI, which mixes up the registers some more. At that point we're lost. I don't see an easy way out of this. I will keep a version of the frame unwinding for perfparser as it's still better than not unwinding at all, but I do understand that it's not really suitable for mainline elfutils. br, Ulf
Re: dwfl_attach_state alternative taking Ebl?
/* [...] Architecture of DWFL modules is specified by ELF, ELF must remain valid during DWFL lifetime. Use NULL ELF to detect architecture from DWFL, the function will then detect it from arbitrary Dwfl_Module of DWFL. [...] */ So would that be an alternative for you? How do you create the Dwfl? Do you add modules to it (how?) and when do you need to call dwfl_attach_state? This is what we do. We parse perf.data. perf.data may contain information about file mappings at any point, and it may take a while until the first valid one shows up. So we postpone dwfl_attach_state until we have a mapping we can resolve to a local elf file. The code would be cleaner if we could attach_state before starting to parse. And there might be pathological cases where no valid elf file can ever be found but we can still unwind by frame pointer. br, Ulf
Re: frame unwinding patches
> That might just mean that the testcase is slightly unrealistic. > Getting a reliable backtrace through signal handlers when not having > full CFI is probably not something we can expect to work. That doesn't > mean having a frame pointer based fallback is a bad thing. We probably > should find a more realistic testcase. And maybe in the future add an > interface to allow people to unwind through "pure CFI" or mixed mode > with frame markers that tell the caller whether the registers can be > trusted or not. The x86_64 case already works with the test case I sent. Maybe we can accept that one before the others. The aarch64 case almost works, but seems to generally duplicate the first entry it unwinds by frame pointer after unwinding anything by CFI. That should be fixable. I will research it and post a follow up patch. The 32bit arm case is a horrible mess and we may indeed need to lower our expectations for that one. Or maybe I can find a raise() that follows the same frame conventions as the gcc I'm using ... br, Ulf
[PATCH v2] Add frame pointer unwinding for aarch64
If we don't find any debug information for a given frame, we usually cannot unwind any further. However, the binary in question might have been compiled with frame pointers, in which case we can look up the well known frame pointer locations in the stack snapshot and use them to bridge the frames without debug information. Change-Id: I3b2285542e368906883579b505e2f45313fede31 Signed-off-by: Ulf Hermann --- backends/ChangeLog | 6 +++ backends/Makefile.am | 2 +- backends/aarch64_init.c| 1 + backends/aarch64_unwind.c | 96 + tests/ChangeLog| 7 +++ tests/Makefile.am | 3 ++ tests/backtrace.aarch64.fp.core.bz2| Bin 0 -> 7302 bytes tests/backtrace.aarch64.fp.exec.bz2| Bin 0 -> 272102 bytes tests/run-backtrace-fp-core-aarch64.sh | 33 9 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 backends/aarch64_unwind.c create mode 100644 tests/backtrace.aarch64.fp.core.bz2 create mode 100755 tests/backtrace.aarch64.fp.exec.bz2 create mode 100755 tests/run-backtrace-fp-core-aarch64.sh diff --git a/backends/ChangeLog b/backends/ChangeLog index eec9923..b8aa1c2 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,5 +1,11 @@ 2017-02-09 Ulf Hermann + * aarch64_unwind.c: New file + * Makefile.am (aarch64_SRCS): Add aarch64_unwind.c + * aarch64_init.c (aarch64_init): Hook aarch64_unwind + +2017-02-09 Ulf Hermann + * x86_64_unwind.c: New file * Makefile.am (x86_64_SRCS): Add x86_64_unwind.c * x86_64_init.c (x86_64_init): Hook x86_64_unwind diff --git a/backends/Makefile.am b/backends/Makefile.am index 60917b9..8e91bd3 100644 --- a/backends/Makefile.am +++ b/backends/Makefile.am @@ -80,7 +80,7 @@ am_libebl_arm_pic_a_OBJECTS = $(arm_SRCS:.c=.os) aarch64_SRCS = aarch64_init.c aarch64_regs.c aarch64_symbol.c \ aarch64_corenote.c aarch64_retval.c aarch64_cfi.c \ - aarch64_initreg.c + aarch64_initreg.c aarch64_unwind.c libebl_aarch64_pic_a_SOURCES = $(aarch64_SRCS) am_libebl_aarch64_pic_a_OBJECTS = $(aarch64_SRCS:.c=.os) diff --git a/backends/aarch64_init.c b/backends/aarch64_init.c index 6395f11..0866494 100644 --- a/backends/aarch64_init.c +++ b/backends/aarch64_init.c @@ -63,6 +63,7 @@ aarch64_init (Elf *elf __attribute__ ((unused)), + ALT_FRAME_RETURN_COLUMN (used when LR isn't used) = 97 DWARF regs. */ eh->frame_nregs = 97; HOOK (eh, set_initial_registers_tid); + HOOK (eh, unwind); return MODVERSION; } diff --git a/backends/aarch64_unwind.c b/backends/aarch64_unwind.c new file mode 100644 index 000..cac4ebd --- /dev/null +++ b/backends/aarch64_unwind.c @@ -0,0 +1,96 @@ +/* Get previous frame state for an existing frame state. + Copyright (C) 2016 The Qt Company Ltd. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + elfutils 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 copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#define BACKEND aarch64_ +#define FP_REG 29 +#define LR_REG 30 +#define SP_REG 31 +#define FP_OFFSET 0 +#define LR_OFFSET 8 +#define SP_OFFSET 16 + +#include "libebl_CPU.h" + +/* There was no CFI. Maybe we happen to have a frame pointer and can unwind from that? */ + +bool +EBLHOOK(unwind) (Ebl *ebl __attribute__ ((unused)), Dwarf_Addr pc __attribute__ ((unused)), + ebl_tid_registers_t *setfunc, ebl_tid_registers_get_t *getfunc, + ebl_pid_memory_read_t *readfunc, void *arg, + bool *signal_framep __attribute__ ((unused))) +{ + Dwarf_Word fp, lr, sp; + + if (!getfunc(LR_REG, 1, &lr, arg)) +return false; + + if (!getfunc(FP_REG, 1, &fp, arg)) +fp = 0; + + if (!getfunc(SP_REG, 1, &sp, arg)) +sp = 0; + + Dwarf_Word newPc, newLr, newFp, newSp; + + // The initial frame is special. We are expected to return lr directly in this case, and we'll + // come back to the same frame again in the next rou
[PATCH] Include sys/types.h before fts.h
The bad fts not only needs to be included before config.h, but also requires various special types without including sys/types.h. Signed-off-by: Ulf Hermann --- libdwfl/ChangeLog | 4 libdwfl/linux-kernel-modules.c | 4 2 files changed, 8 insertions(+) diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index ede6d47..1ed9dd4 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,7 @@ +2017-04-20 Ulf Hermann + + * linux-kernel-modules.c: Include sys/types.h before fts.h + 2017-03-24 Mark Wielaard * linux-core-attach.c (core_next_thread): If n_namesz == 0 then diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c index 7345e76..757eace 100644 --- a/libdwfl/linux-kernel-modules.c +++ b/libdwfl/linux-kernel-modules.c @@ -26,6 +26,10 @@ the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* Include sys/types.h before fts. On some systems fts.h is not self + contained. */ +#include + /* In case we have a bad fts we include this before config.h because it can't handle _FILE_OFFSET_BITS. Everything we need here is fine if its declarations just come first. */ -- 2.1.4
[PATCH] Clean up linux-specific system includes
We only include them where we actually need them and only on linux. Change-Id: Ic3065ffab67ba1177f63204fb91a92c5f4336dbb Signed-off-by: Ulf Hermann --- backends/ChangeLog | 8 backends/aarch64_initreg.c | 4 ++-- backends/arm_initreg.c | 4 +++- backends/ppc_initreg.c | 4 ++-- backends/s390_initreg.c| 4 ++-- backends/x86_64_initreg.c | 2 +- libdwfl/ChangeLog | 7 +++ libdwfl/dwfl_frame.c | 1 - libdwfl/frame_unwind.c | 1 - libdwfl/linux-pid-attach.c | 5 +++-- tests/ChangeLog| 5 + tests/backtrace-child.c| 2 +- tests/backtrace-dwarf.c| 2 +- 13 files changed, 35 insertions(+), 14 deletions(-) diff --git a/backends/ChangeLog b/backends/ChangeLog index 39390cb..c6e0e08 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,11 @@ +2017-04-20 Ulf Hermann + + * aarch64_initreg.c: Compile register initialization only on linux. + * arm_initreg.c: Likewise. + * ppc_initreg.c: Likewise. + * s390_initreg.c: Likewise. + * x86_64_initreg.c: Likewise. + 2017-02-15 Mark Wielaard * ppc64_init.c (ppc64_init): Add check_object_attribute HOOK. diff --git a/backends/aarch64_initreg.c b/backends/aarch64_initreg.c index 9706205..daf6f37 100644 --- a/backends/aarch64_initreg.c +++ b/backends/aarch64_initreg.c @@ -32,7 +32,7 @@ #include "system.h" #include -#ifdef __aarch64__ +#if defined(__aarch64__) && defined(__linux__) # include # include # include @@ -51,7 +51,7 @@ aarch64_set_initial_registers_tid (pid_t tid __attribute__ ((unused)), ebl_tid_registers_t *setfunc __attribute__ ((unused)), void *arg __attribute__ ((unused))) { -#ifndef __aarch64__ +#if !defined(__aarch64__) || !defined(__linux__) return false; #else /* __aarch64__ */ diff --git a/backends/arm_initreg.c b/backends/arm_initreg.c index a0a9be9..efcabaf 100644 --- a/backends/arm_initreg.c +++ b/backends/arm_initreg.c @@ -30,6 +30,7 @@ # include #endif +#ifdef __linux__ #if defined __arm__ # include # include @@ -45,6 +46,7 @@ # define user_regs_struct user_pt_regs # endif #endif +#endif #define BACKEND arm_ #include "libebl_CPU.h" @@ -54,7 +56,7 @@ arm_set_initial_registers_tid (pid_t tid __attribute__ ((unused)), ebl_tid_registers_t *setfunc __attribute__ ((unused)), void *arg __attribute__ ((unused))) { -#if !defined __arm__ && !defined __aarch64__ +#if !defined(__linux__) || (!defined __arm__ && !defined __aarch64__) return false; #else /* __arm__ || __aarch64__ */ #if defined __arm__ diff --git a/backends/ppc_initreg.c b/backends/ppc_initreg.c index 64f5379..69d623b 100644 --- a/backends/ppc_initreg.c +++ b/backends/ppc_initreg.c @@ -32,7 +32,7 @@ #include "system.h" #include -#ifdef __powerpc__ +#if defined(__powerpc__) && defined(__linux__) # include # include #endif @@ -70,7 +70,7 @@ ppc_set_initial_registers_tid (pid_t tid __attribute__ ((unused)), ebl_tid_registers_t *setfunc __attribute__ ((unused)), void *arg __attribute__ ((unused))) { -#ifndef __powerpc__ +#if !defined(__powerpc__) || !defined(__linux__) return false; #else /* __powerpc__ */ union diff --git a/backends/s390_initreg.c b/backends/s390_initreg.c index b4c4b67..011305c 100644 --- a/backends/s390_initreg.c +++ b/backends/s390_initreg.c @@ -32,7 +32,7 @@ #include "system.h" #include -#ifdef __s390__ +#if defined(__s390__) && defined(__linux__) # include # include # include @@ -46,7 +46,7 @@ s390_set_initial_registers_tid (pid_t tid __attribute__ ((unused)), ebl_tid_registers_t *setfunc __attribute__ ((unused)), void *arg __attribute__ ((unused))) { -#ifndef __s390__ +#if !defined(__s390__) || !defined(__linux__) return false; #else /* __s390__ */ struct user user_regs; diff --git a/backends/x86_64_initreg.c b/backends/x86_64_initreg.c index db9216e..50e9002 100644 --- a/backends/x86_64_initreg.c +++ b/backends/x86_64_initreg.c @@ -31,7 +31,7 @@ #endif #include -#ifdef __x86_64__ +#if defined(__x86_64__) && defined(__linux__) # include # include #endif diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 1ed9dd4..705b93d 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,5 +1,12 @@ 2017-04-20 Ulf Hermann + * dwfl_frame.c: Drop unused sys/ptrace.h include. + * frame_unwind.c: Likewise. + * linux-pid-attach.c: Include sys/ptrace.h and sys/syscall.h only on + linux. + +2017-04-20 Ulf Hermann + * linux-kernel-modules.c: Include sys/types.h before fts.h 2017-03-24 Mark Wielaard diff --git a/libdwfl/dwfl_frame.c b/libdwfl/dwfl_frame.c index d639939..1dc0c8d 100644 --- a/libdwfl/dwfl_frame.
[PATCH] Don't use comparison_fn_t
Not all search.h declare it, and it is not very helpful anyway. Signed-off-by: Ulf Hermann --- libcpu/ChangeLog| 4 libcpu/i386_parse.y | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog index 79110c2..ec22dd2 100644 --- a/libcpu/ChangeLog +++ b/libcpu/ChangeLog @@ -1,3 +1,7 @@ +2017-04-20 Ulf Hermann + + * i386_parse.y: Eliminate comparison_fn_t. + 2016-11-02 Mark Wielaard * i386_disasm.c (i386_disasm): Add fallthrough comment. diff --git a/libcpu/i386_parse.y b/libcpu/i386_parse.y index 15a72b1..5fc0682 100644 --- a/libcpu/i386_parse.y +++ b/libcpu/i386_parse.y @@ -309,10 +309,10 @@ instr: bytes ':' bitfieldopt kID bitfieldopt optargs newp->mnemonic = $4; if (newp->mnemonic != (void *) -1l && tfind ($4, &mnemonics, - (comparison_fn_t) strcmp) == NULL) + (int (*)(const void *, const void *)) strcmp) == NULL) { if (tsearch ($4, &mnemonics, - (comparison_fn_t) strcmp) == NULL) + (int (*)(const void *, const void *)) strcmp) == NULL) error (EXIT_FAILURE, errno, "tsearch"); ++nmnemonics; } -- 2.1.4
[PATCH] Avoid YESSTR and NOSTR
Those are deprecated and apparently some implementations of nl_langinfo return empty strings for them. The tests even tested for those empty strings even though the intention of the code was clearly to output "yes" or "no" there. Signed-off-by: Ulf Hermann --- src/ChangeLog | 5 + src/readelf.c | 6 +++--- tests/ChangeLog | 6 ++ tests/run-readelf-dwz-multi.sh | 30 +++--- tests/run-readelf-zdebug-rel.sh | 6 +++--- 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index a1bec19..e0a591e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2017-04-20 Ulf Hermann + + * readelf.c: Replace YESSTR and NOSTR with gettext ("yes") and + gettext ("no"), respectively. + 2017-04-05 Mark Wielaard * elflint.c (check_elf_header): Decompress all sections. diff --git a/src/readelf.c b/src/readelf.c index 97a43b0..6f6095d 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -6132,7 +6132,7 @@ attr_callback (Dwarf_Attribute *attrp, void *arg) printf (" %*s%-20s (%s) %s\n", (int) (level * 2), "", dwarf_attr_name (attr), - dwarf_form_name (form), nl_langinfo (flag ? YESSTR : NOSTR)); + dwarf_form_name (form), flag ? gettext ("yes") : gettext ("no")); break; case DW_FORM_flag_present: @@ -6140,7 +6140,7 @@ attr_callback (Dwarf_Attribute *attrp, void *arg) break; printf (" %*s%-20s (%s) %s\n", (int) (level * 2), "", dwarf_attr_name (attr), - dwarf_form_name (form), nl_langinfo (YESSTR)); + dwarf_form_name (form), gettext ("yes")); break; case DW_FORM_exprloc: @@ -7650,7 +7650,7 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)), if (readp + 1 > readendp) goto invalid_data; val = *readp++; - printf (" %s", nl_langinfo (val != 0 ? YESSTR : NOSTR)); + printf (" %s", val != 0 ? gettext ("yes") : gettext ("no")); break; case DW_FORM_string: diff --git a/tests/ChangeLog b/tests/ChangeLog index ebcd7bc..c4e76d1 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,5 +1,11 @@ 2017-04-20 Ulf Hermann + * run-readelf-dwz-multi.sh: Expect readelf to output "yes" for flags + that are set. + * run-readelf-zdebug-rel.sh: Likewise. + +2017-04-20 Ulf Hermann + * backtrace-child.c: Include sys/ptrace.h only on linux. * backtrace-dwarf.c: Likewise. diff --git a/tests/run-readelf-dwz-multi.sh b/tests/run-readelf-dwz-multi.sh index 27e0f38..23ca944 100755 --- a/tests/run-readelf-dwz-multi.sh +++ b/tests/run-readelf-dwz-multi.sh @@ -98,17 +98,17 @@ DWARF section [28] '.debug_info' at offset 0x1078: byte_size(data1) 8 type (GNU_ref_alt) [53] [31]subprogram - external (flag_present) + external (flag_present) yes name (strp) "main" decl_file(data1) 1 decl_line(data1) 3 - prototyped (flag_present) + prototyped (flag_present) yes type (GNU_ref_alt) [3e] low_pc (addr) 0x004006ac high_pc (udata) 44 (0x004006d8) frame_base (exprloc) [ 0] call_frame_cfa - GNU_all_tail_call_sites (flag_present) + GNU_all_tail_call_sites (flag_present) yes sibling (ref_udata) [6e] [48] formal_parameter name (strp) "argc" @@ -159,17 +159,17 @@ DWARF section [28] '.debug_info' at offset 0x1078: byte_size(data1) 8 type (GNU_ref_alt) [53] [31]subprogram - external (flag_present) + external (flag_present) yes name (strp) "main" decl_file(data1) 1 decl_line(data1) 3 - prototyped (flag_present) + prototyped (flag_present) yes type (GNU_ref_alt) [3e] low_pc (addr) 0x004006ac high_pc (udata) 44 (0x004006d8) frame_base (exprloc) [ 0] call_frame_cfa -
[PATCH] Make __attribute__ conditional in all installed headers
__attribute__ is a GNU extension. If we want to link against the libraries using a different compiler, it needs to be disabled. It was already disabled in libdw.h, and this patch extends this to the other headers. We move the defines to libelf.h as that is included in all the others. Signed-off-by: Ulf Hermann --- libdw/ChangeLog | 5 + libdw/libdw.h | 23 +-- libdwfl/ChangeLog | 4 libdwfl/libdwfl.h | 2 +- libebl/ChangeLog | 4 libebl/libebl.h | 6 +++--- libelf/ChangeLog | 5 + libelf/libelf.h | 38 +++--- 8 files changed, 54 insertions(+), 33 deletions(-) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 3f63a17..c9ae664 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,8 @@ +2017-04-20 Ulf Hermann + + * libdw.h: Remove attribute macro declarations and use + __noreturn_attribute__ as defined in libelf.h. + 2017-03-30 Mark Wielaard * dwarf_peel_type.c (dwarf_peel_type): Call dwarf_attr_integrate on diff --git a/libdw/libdw.h b/libdw/libdw.h index 473e1a2..9ae80eb 100644 --- a/libdw/libdw.h +++ b/libdw/libdw.h @@ -34,23 +34,6 @@ #include #include - -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) -# define __nonnull_attribute__(...) __attribute__ ((__nonnull__ (__VA_ARGS__))) -# define __deprecated_attribute__ __attribute__ ((__deprecated__)) -#else -# define __nonnull_attribute__(args...) -# define __deprecated_attribute__ -#endif - - -#ifdef __GNUC_STDC_INLINE__ -# define __libdw_extern_inline extern __inline __attribute__ ((__gnu_inline__)) -#else -# define __libdw_extern_inline extern __inline -#endif - - /* Mode for the session. */ typedef enum { @@ -242,11 +225,7 @@ typedef struct Dwarf Dwarf; /* Out-Of-Memory handler. */ -#if __GNUC__ < 4 -typedef void (*Dwarf_OOM) (void); -#else -typedef void (*__attribute__ ((noreturn)) Dwarf_OOM) (void); -#endif +typedef void (*__noreturn_attribute__ Dwarf_OOM) (void); #ifdef __cplusplus diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 705b93d..0a572ad 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,7 @@ +2017-04-20 Ulf Hermann + + * libdwfl.h: Use __const_attribute__. + 2017-04-20 Ulf Hermann * dwfl_frame.c: Drop unused sys/ptrace.h include. diff --git a/libdwfl/libdwfl.h b/libdwfl/libdwfl.h index aea8b99..a0c1d35 100644 --- a/libdwfl/libdwfl.h +++ b/libdwfl/libdwfl.h @@ -385,7 +385,7 @@ extern int dwfl_linux_proc_find_elf (Dwfl_Module *mod, void **userdata, /* Standard argument parsing for using a standard callback set. */ struct argp; -extern const struct argp *dwfl_standard_argp (void) __attribute__ ((const)); +extern const struct argp *dwfl_standard_argp (void) __const_attribute__; /*** Relocation of addresses from Dwfl ***/ diff --git a/libebl/ChangeLog b/libebl/ChangeLog index 719d08d..506915b 100644 --- a/libebl/ChangeLog +++ b/libebl/ChangeLog @@ -1,3 +1,7 @@ +2017-04-20 Ulf Hermann + + * libebl.h: Use __pure_attribute__. + 2017-02-15 Ulf Hermann * eblmachineflagname.c: Include system.h. diff --git a/libebl/libebl.h b/libebl/libebl.h index c8e01fe..87896e4 100644 --- a/libebl/libebl.h +++ b/libebl/libebl.h @@ -73,13 +73,13 @@ extern void ebl_closebackend (Ebl *bh); /* Information about the descriptor. */ /* Get ELF machine. */ -extern int ebl_get_elfmachine (Ebl *ebl) __attribute__ ((__pure__)); +extern int ebl_get_elfmachine (Ebl *ebl) __pure_attribute__; /* Get ELF class. */ -extern int ebl_get_elfclass (Ebl *ebl) __attribute__ ((__pure__)); +extern int ebl_get_elfclass (Ebl *ebl) __pure_attribute__; /* Get ELF data encoding. */ -extern int ebl_get_elfdata (Ebl *ebl) __attribute__ ((__pure__)); +extern int ebl_get_elfdata (Ebl *ebl) __pure_attribute__; /* Function to call the callback functions including default ELF diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 23a4fb9..23cd942 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,8 @@ +2017-04-20 Ulf Hermann + + * libelf.h: Define macros for various function attributes and use + them. + 2017-03-27 Mark Wielaard * elf32_updatefile.c (updatemmap): Always update last_positition. diff --git a/libelf/libelf.h b/libelf/libelf.h index c0d6389..547c0f5 100644 --- a/libelf/libelf.h +++ b/libelf/libelf.h @@ -64,6 +64,30 @@ #define ELFCOMPRESS_HIPROC 0x7fff /* End of processor-specific. */ #endif +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) +# define __nonnull_attribute__(...) __attribute__ ((__nonnull__ (__VA_ARGS__))) +# define __deprecated_attribute__ __attribute__ ((__deprecated__)) +# define __pure_attribute__ __attribute__ ((__pure__)) +# define __const_attribute__ __attribute__ ((__const__)) +#else +# define __nonnull_attribute__(...) +# define __deprecated_attribute__ +# define __pure_attribute__ +# define __const_attribut
[PATCH] Use F_GETFD rather than F_GETFL to check validity of file descriptor
F_GETFD is both cheaper and easier to port, and otherwise has the same effect here. Signed-off-by: Ulf Hermann --- libelf/ChangeLog | 4 libelf/elf_begin.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 23cd942..e32590a 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,5 +1,9 @@ 2017-04-20 Ulf Hermann + * elf_begin.c: Use F_GETFD rather than F_GETFL. + +2017-04-20 Ulf Hermann + * libelf.h: Define macros for various function attributes and use them. diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c index 5e9099c..6f85038 100644 --- a/libelf/elf_begin.c +++ b/libelf/elf_begin.c @@ -1075,7 +1075,7 @@ elf_begin (int fildes, Elf_Cmd cmd, Elf *ref) if (ref != NULL) /* Make sure the descriptor is not suddenly going away. */ rwlock_rdlock (ref->lock); - else if (unlikely (fcntl (fildes, F_GETFL) == -1 && errno == EBADF)) + else if (unlikely (fcntl (fildes, F_GETFD) == -1 && errno == EBADF)) { /* We cannot do anything productive without a file descriptor. */ __libelf_seterrno (ELF_E_INVALID_FILE); -- 2.1.4
[PATCH] Protect against integer overflow on shnum
If shnum is 0, the many "shnum - 1" would result in an overflow. Check it for 0, and only subtract once, rather than on every usage. Signed-off-by: Ulf Hermann --- libdwfl/ChangeLog | 5 + libdwfl/dwfl_module_getdwarf.c | 18 ++ src/ChangeLog | 4 src/unstrip.c | 25 ++--- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 0a572ad..de73d79 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,5 +1,10 @@ 2017-04-20 Ulf Hermann + * dwfl_module_getdwarf.c: Check shnum for 0 before subtracting from + it. + +2017-04-20 Ulf Hermann + * libdwfl.h: Use __const_attribute__. 2017-04-20 Ulf Hermann diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c index 46caece..c8b839d 100644 --- a/libdwfl/dwfl_module_getdwarf.c +++ b/libdwfl/dwfl_module_getdwarf.c @@ -349,12 +349,14 @@ find_prelink_address_sync (Dwfl_Module *mod, struct dwfl_file *file) /* Since prelink does not store the zeroth section header in the undo section, it cannot support SHN_XINDEX encoding. */ - if (unlikely (shnum >= SHN_LORESERVE) + if (unlikely (shnum >= SHN_LORESERVE) || unlikely(shnum == 0) || unlikely (undodata->d_size != (src.d_size + phnum * phentsize + (shnum - 1) * shentsize))) return DWFL_E_BAD_PRELINK; + --shnum; + /* We look at the allocated SHT_PROGBITS (or SHT_NOBITS) sections. (Most every file will have some SHT_PROGBITS sections, but it's possible to have one with nothing but .bss, i.e. SHT_NOBITS.) The special sections @@ -431,12 +433,12 @@ find_prelink_address_sync (Dwfl_Module *mod, struct dwfl_file *file) src.d_buf += src.d_size; src.d_type = ELF_T_SHDR; - src.d_size = gelf_fsize (mod->main.elf, ELF_T_SHDR, shnum - 1, EV_CURRENT); + src.d_size = gelf_fsize (mod->main.elf, ELF_T_SHDR, shnum, EV_CURRENT); size_t shdr_size = class32 ? sizeof (Elf32_Shdr) : sizeof (Elf64_Shdr); - if (unlikely (shnum - 1 > SIZE_MAX / shdr_size)) + if (unlikely (shnum > SIZE_MAX / shdr_size)) return DWFL_E_NOMEM; - const size_t shdrs_bytes = (shnum - 1) * shdr_size; + const size_t shdrs_bytes = shnum * shdr_size; void *shdrs = malloc (shdrs_bytes); if (unlikely (shdrs == NULL)) return DWFL_E_NOMEM; @@ -488,16 +490,16 @@ find_prelink_address_sync (Dwfl_Module *mod, struct dwfl_file *file) highest = 0; if (class32) { - Elf32_Shdr (*s32)[shnum - 1] = shdrs; - for (size_t i = 0; i < shnum - 1; ++i) + Elf32_Shdr (*s32)[shnum] = shdrs; + for (size_t i = 0; i < shnum; ++i) consider_shdr (undo_interp, (*s32)[i].sh_type, (*s32)[i].sh_flags, (*s32)[i].sh_addr, (*s32)[i].sh_size, &highest); } else { - Elf64_Shdr (*s64)[shnum - 1] = shdrs; - for (size_t i = 0; i < shnum - 1; ++i) + Elf64_Shdr (*s64)[shnum] = shdrs; + for (size_t i = 0; i < shnum; ++i) consider_shdr (undo_interp, (*s64)[i].sh_type, (*s64)[i].sh_flags, (*s64)[i].sh_addr, (*s64)[i].sh_size, &highest); diff --git a/src/ChangeLog b/src/ChangeLog index e0a591e..1521d80 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2017-04-20 Ulf Hermann + + * unstrip.c: Check shnum for 0 before subtracting from it. + 2017-04-20 Ulf Hermann * readelf.c: Replace YESSTR and NOSTR with gettext ("yes") and diff --git a/src/unstrip.c b/src/unstrip.c index 6e57a6b..5074909 100644 --- a/src/unstrip.c +++ b/src/unstrip.c @@ -1027,21 +1027,24 @@ find_alloc_sections_prelink (Elf *debug, Elf_Data *debug_shstrtab, shnum = ehdr.e64.e_shnum; } + bool class32 = ehdr.e32.e_ident[EI_CLASS] == ELFCLASS32; + size_t shsize = class32 ? sizeof (Elf32_Shdr) : sizeof (Elf64_Shdr); + if (unlikely (shnum == 0 || shnum > SIZE_MAX / shsize + 1)) + error (EXIT_FAILURE, 0, _("overflow with shnum = %zu in '%s' section"), + (size_t) shnum, ".gnu.prelink_undo"); + + --shnum; + size_t phsize = gelf_fsize (main, ELF_T_PHDR, phnum, EV_CURRENT); src.d_buf += src.d_size + phsize; - src.d_size = gelf_fsize (main, ELF_T_SHDR, shnum - 1, EV_CURRENT); + src.d_size = gelf_fsize (main, ELF_T_SHDR, shnum, EV_CURRENT); src.d_type = ELF_T_SHDR; if ((size_t) (src.d_buf - undodata->d_buf) > undodata->d_size || undodata->d_size - (src.d_buf - undodata->d_buf) != src.d_size) error (EXIT_FAILURE, 0, _("invalid contents in '%s' section"), ".gnu.prel
[PATCH] Don't look for kernel version if not running on linux
We don't want to use it, even if it exists. Signed-off-by: Ulf Hermann --- libdwfl/ChangeLog | 5 + libdwfl/linux-kernel-modules.c | 4 2 files changed, 9 insertions(+) diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index de73d79..80346d5 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,5 +1,10 @@ 2017-04-20 Ulf Hermann + * linux-kernel-modules.c: Always return NULL from kernel_release() on + non-linux systems. + +2017-04-20 Ulf Hermann + * dwfl_module_getdwarf.c: Check shnum for 0 before subtracting from it. diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c index 757eace..381711a 100644 --- a/libdwfl/linux-kernel-modules.c +++ b/libdwfl/linux-kernel-modules.c @@ -156,11 +156,15 @@ try_kernel_name (Dwfl *dwfl, char **fname, bool try_debug) static inline const char * kernel_release (void) { +#ifdef __linux__ /* Cache the `uname -r` string we'll use. */ static struct utsname utsname; if (utsname.release[0] == '\0' && uname (&utsname) != 0) return NULL; return utsname.release; +#else + return NULL; +#endif } static int -- 2.1.4
[PATCH] Avoid double-including config.h
config.h doesn't have include guards, so including it twice is bad. We deal with this by checking for PACKAGE_NAME, but only in some places. Once we start using gnulib, we will need to include config.h before any gnulib-generated headers. This is problematic if we include it transitively through our own private headers. In order to set a clear rule about inclusion of config.h, it is now included in every .c file as first header, but not in any header. This will definitely avoid double-inclusion and satisfy the condition that it has to be included before gnulib headers. It comes at the price of adding some redundancy, but there is no clean way to avoid this. Signed-off-by: Ulf Hermann --- lib/ChangeLog | 5 +++ lib/crc32.c | 4 ++ lib/system.h| 4 -- libdwfl/ChangeLog | 58 + libdwfl/argp-std.c | 4 ++ libdwfl/cu.c| 4 ++ libdwfl/derelocate.c| 4 ++ libdwfl/dwfl_addrdie.c | 4 ++ libdwfl/dwfl_addrdwarf.c| 4 ++ libdwfl/dwfl_addrmodule.c | 4 ++ libdwfl/dwfl_begin.c| 4 ++ libdwfl/dwfl_build_id_find_debuginfo.c | 4 ++ libdwfl/dwfl_build_id_find_elf.c| 4 ++ libdwfl/dwfl_cumodule.c | 4 ++ libdwfl/dwfl_dwarf_line.c | 4 ++ libdwfl/dwfl_end.c | 4 ++ libdwfl/dwfl_frame.c| 4 ++ libdwfl/dwfl_frame_regs.c | 4 ++ libdwfl/dwfl_getdwarf.c | 4 ++ libdwfl/dwfl_getmodules.c | 4 ++ libdwfl/dwfl_getsrc.c | 4 ++ libdwfl/dwfl_getsrclines.c | 4 ++ libdwfl/dwfl_line_comp_dir.c| 4 ++ libdwfl/dwfl_linecu.c | 4 ++ libdwfl/dwfl_lineinfo.c | 4 ++ libdwfl/dwfl_linemodule.c | 4 ++ libdwfl/dwfl_module.c | 4 ++ libdwfl/dwfl_module_addrdie.c | 4 ++ libdwfl/dwfl_module_addrname.c | 4 ++ libdwfl/dwfl_module_addrsym.c | 4 ++ libdwfl/dwfl_module_build_id.c | 4 ++ libdwfl/dwfl_module_dwarf_cfi.c | 4 ++ libdwfl/dwfl_module_eh_cfi.c| 4 ++ libdwfl/dwfl_module_getdwarf.c | 4 ++ libdwfl/dwfl_module_getelf.c| 4 ++ libdwfl/dwfl_module_getsrc.c| 4 ++ libdwfl/dwfl_module_getsrc_file.c | 4 ++ libdwfl/dwfl_module_getsym.c| 4 ++ libdwfl/dwfl_module_info.c | 4 ++ libdwfl/dwfl_module_nextcu.c| 4 ++ libdwfl/dwfl_module_register_names.c| 4 ++ libdwfl/dwfl_module_report_build_id.c | 4 ++ libdwfl/dwfl_module_return_value_location.c | 4 ++ libdwfl/dwfl_nextcu.c | 4 ++ libdwfl/dwfl_onesrcline.c | 4 ++ libdwfl/dwfl_report_elf.c | 4 ++ libdwfl/dwfl_validate_address.c | 4 ++ libdwfl/dwfl_version.c | 4 ++ libdwfl/find-debuginfo.c| 4 ++ libdwfl/gzip.c | 4 ++ libdwfl/image-header.c | 4 ++ libdwfl/libdwflP.h | 3 -- libdwfl/lines.c | 4 ++ libdwfl/linux-core-attach.c | 4 ++ libdwfl/linux-pid-attach.c | 4 ++ libdwfl/linux-proc-maps.c | 4 ++ libdwfl/offline.c | 4 ++ libdwfl/open.c | 4 ++ libdwfl/relocate.c | 4 ++ libdwfl/segment.c | 4 ++ libelf/ChangeLog| 4 ++ libelf/libelfP.h| 4 -- 62 files changed, 291 insertions(+), 11 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 84290f7..8cac7af 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,8 @@ +2017-04-20 Ulf Hermann + + * crc32.c: include config.h. + * system.h: Don't include config.h. + 2017-02-16 Ulf Hermann * Makefile.am (libeu_a_SOURCES): Remove version.c, add printversion.c diff --git a/lib/crc32.c b/lib/crc32.c index 1a76b1b..758602e 100644 --- a/lib/crc32.c +++ b/lib/crc32.c @@ -25,6 +25,10 @@ the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#if HAVE_CONFIG_H +#include +#endif + #include #include "system.h" diff --git a/lib/system.h b/lib/system.h index 2d05702..9203335 100644 --- a/lib/system.h +++ b/lib/system.h @@ -29,10 +29,6 @@ #ifndef LIB_SYSTEM_H #define LIB_SYSTEM_H 1 -#ifdef HAVE_CONFIG_H -# include -#endif - #include
[PATCH] Include strings.h to make ffs available
We cannot rely on it to be available from any of the other headers. Signed-off-by: Ulf Hermann --- src/ChangeLog | 4 src/readelf.c | 1 + 2 files changed, 5 insertions(+) diff --git a/src/ChangeLog b/src/ChangeLog index 1521d80..cbb77fc 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,9 @@ 2017-04-20 Ulf Hermann + * readelf.c: Include strings.h. + +2017-04-20 Ulf Hermann + * unstrip.c: Check shnum for 0 before subtracting from it. 2017-04-20 Ulf Hermann diff --git a/src/readelf.c b/src/readelf.c index 6f6095d..40d4913 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include -- 2.1.4
[PATCH] Avoid signed/unsigned comparison
Some compilers implicitly cast the result of uint_fast16_t * uint_fast16_t to something signed and then complain about the comparison to (unsigned) size_t. Casting phnum to size_t is a good idea anyway as 16bit multiplication can easily overflow and we are not checking for this. Signed-off-by: Ulf Hermann --- libdwfl/ChangeLog | 4 libdwfl/elf-from-memory.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index cddafe2..c9bd4f0 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,5 +1,9 @@ 2017-04-20 Ulf Hermann + * elf-from-memory.c: Explicitly cast phnum to size_t. + +2017-04-20 Ulf Hermann + * libdwflP.h: Don't include config.h. * argp-std.c: Include config.h. * cu.c: Likewise. diff --git a/libdwfl/elf-from-memory.c b/libdwfl/elf-from-memory.c index dd42e95..12a0a1b 100644 --- a/libdwfl/elf-from-memory.c +++ b/libdwfl/elf-from-memory.c @@ -172,7 +172,7 @@ elf_from_remote_memory (GElf_Addr ehdr_vma, { /* Read in the program headers. */ - if (initial_bufsize < phnum * phentsize) + if (initial_bufsize < (size_t)phnum * phentsize) { unsigned char *newbuf = realloc (buffer, phnum * phentsize); if (newbuf == NULL) -- 2.1.4
[PATCH v2] Include sys/types.h before fts.h
The bad fts not only needs to be included before config.h, but also requires various special types without including sys/types.h. Change-Id: I31ac8d2aadcf7ffb3efb63583b2745991bfd6f90 Signed-off-by: Ulf Hermann --- libdwfl/ChangeLog | 4 libdwfl/linux-kernel-modules.c | 6 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index ede6d47..cc95e06 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,7 @@ +2017-04-20 Ulf Hermann + + * linux-kernel-modules.c: Include sys/types.h before fts.h + 2017-03-24 Mark Wielaard * linux-core-attach.c (core_next_thread): If n_namesz == 0 then diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c index 7345e76..893110a 100644 --- a/libdwfl/linux-kernel-modules.c +++ b/libdwfl/linux-kernel-modules.c @@ -28,8 +28,11 @@ /* In case we have a bad fts we include this before config.h because it can't handle _FILE_OFFSET_BITS. - Everything we need here is fine if its declarations just come first. */ + Everything we need here is fine if its declarations just come first. + Also, include sys/types.h before fts. On some systems fts.h is not self + contained. */ #ifdef BAD_FTS + #include #include #endif @@ -55,6 +58,7 @@ #define fopen fopen64 #endif #else + #include #include #endif -- 2.1.4
[PATCH] Make elf section sorting more deterministic
At least one test (dwfl-addr-sect) depends on the order of elf sections with equal addresses. This is not guaranteed by the code. Compare also by end address and name to tell entries apart. Signed-off-by: Ulf Hermann --- libdwfl/ChangeLog | 5 + libdwfl/derelocate.c| 17 +++-- tests/ChangeLog | 6 ++ tests/run-dwfl-addr-sect.sh | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index f605f46..a1ed675 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,5 +1,10 @@ 2017-04-20 Ulf Hermann + * derelocate.c (compare_secrefs): Compare by end address and then by + name if start addresses are equal. + +2017-04-20 Ulf Hermann + * elf-from-memory.c: Explicitly cast phnum to size_t. 2017-04-20 Ulf Hermann diff --git a/libdwfl/derelocate.c b/libdwfl/derelocate.c index e5c3e12..8d965af 100644 --- a/libdwfl/derelocate.c +++ b/libdwfl/derelocate.c @@ -57,17 +57,22 @@ struct secref static int compare_secrefs (const void *a, const void *b) { - struct secref *const *p1 = a; - struct secref *const *p2 = b; + struct secref const *p1 = *(struct secref *const *)a; + struct secref const *p2 = *(struct secref *const *)b; /* No signed difference calculation is correct here, since the terms are unsigned and could be more than INT64_MAX apart. */ - if ((*p1)->start < (*p2)->start) + if (p1->start < p2->start) return -1; - if ((*p1)->start > (*p2)->start) + if (p1->start > p2->start) return 1; - - return 0; + if (p1->end < p2->end) +return -1; + if (p1->end > p2->end) +return 1; + if (p1->name == NULL) +return p2->name == NULL ? 0 : -1; + return p2->name == NULL ? 1 : strcmp(p1->name, p2->name); } static int diff --git a/tests/ChangeLog b/tests/ChangeLog index c4e76d1..4da049b 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,5 +1,11 @@ 2017-04-20 Ulf Hermann + * run-dwfl-addr-sect.sh: Expect section with alphabetically smaller + name when requesting the start address of two otherwise equal + zero-sized sections. + +2017-04-20 Ulf Hermann + * run-readelf-dwz-multi.sh: Expect readelf to output "yes" for flags that are set. * run-readelf-zdebug-rel.sh: Likewise. diff --git a/tests/run-dwfl-addr-sect.sh b/tests/run-dwfl-addr-sect.sh index 80da008..e257bfc 100755 --- a/tests/run-dwfl-addr-sect.sh +++ b/tests/run-dwfl-addr-sect.sh @@ -20,7 +20,7 @@ testfiles testfile43 testfile50 testrun_compare ${abs_builddir}/dwfl-addr-sect -e testfile43 0x64 0x8 0x98 <<\EOF -address 0x64 => module "" section 4 + 0 +address 0x64 => module "" section 3 + 0 address 0x8 => module "" section 1 + 0x8 address 0x98 => module "" section 7 + 0 EOF -- 2.1.4
[PATCH] On elf_update, remember when we mmap()
Otherwise we skip the munmap() later. This leaks resources. Signed-off-by: Ulf Hermann --- libelf/ChangeLog| 4 libelf/elf_update.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/libelf/ChangeLog b/libelf/ChangeLog index fa768f8..225c7c8 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,5 +1,9 @@ 2017-04-20 Ulf Hermann + * elf_update.c: Set ELF_F_MMAPPED flag if we mmap from elf_update. + +2017-04-20 Ulf Hermann + * libelfP.h: Don't include config.h. 2017-04-20 Ulf Hermann diff --git a/libelf/elf_update.c b/libelf/elf_update.c index c635eb3..8ce0782 100644 --- a/libelf/elf_update.c +++ b/libelf/elf_update.c @@ -74,6 +74,8 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum) MAP_SHARED, elf->fildes, 0); if (unlikely (elf->map_address == MAP_FAILED)) elf->map_address = NULL; + else + elf->flags |= ELF_F_MMAPPED; } if (elf->map_address != NULL) -- 2.1.4
[PATCH] Add EXEEXT to gendis
Otherwise the build will fail on systems that actually need file extension for executables. Signed-off-by: Ulf Hermann --- libcpu/ChangeLog | 4 libcpu/Makefile.am | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog index e59e876..7fe4345 100644 --- a/libcpu/ChangeLog +++ b/libcpu/ChangeLog @@ -1,5 +1,9 @@ 2017-04-20 Ulf Hermann + * Makefile.am: Add EXEEXT to gendis. + +2017-04-20 Ulf Hermann + * i386_parse.y: Eliminate comparison_fn_t. 2016-11-02 Mark Wielaard diff --git a/libcpu/Makefile.am b/libcpu/Makefile.am index b98b583..31fc906 100644 --- a/libcpu/Makefile.am +++ b/libcpu/Makefile.am @@ -58,10 +58,10 @@ endif if MAINTAINER_MODE noinst_HEADERS = memory-access.h i386_parse.h i386_data.h -noinst_PROGRAMS = i386_gendis +noinst_PROGRAMS = i386_gendis$(EXEEXT) -$(srcdir)/%_dis.h: %_defs i386_gendis - $(AM_V_GEN)./i386_gendis $< > $@T +$(srcdir)/%_dis.h: %_defs i386_gendis$(EXEEXT) + $(AM_V_GEN)./i386_gendis$(EXEEXT) $< > $@T $(AM_V_at)mv -f $@T $@ else -- 2.1.4
[PATCH] Include endian.h when handling BYTE_ORDER
BYTE_ORDER and friends are customarily defined in endian.h. Signed-off-by: Ulf Hermann --- libdw/ChangeLog | 4 libdw/dwarf_begin_elf.c | 1 + 2 files changed, 5 insertions(+) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index c9ae664..8802853 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,5 +1,9 @@ 2017-04-20 Ulf Hermann + * dwarf_begin_elf.c: Include endian.h. + +2017-04-20 Ulf Hermann + * libdw.h: Remove attribute macro declarations and use __noreturn_attribute__ as defined in libelf.h. diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c index 6f25e42..afa15ce 100644 --- a/libdw/dwarf_begin_elf.c +++ b/libdw/dwarf_begin_elf.c @@ -41,6 +41,7 @@ #include #include #include +#include #include "libdwP.h" -- 2.1.4
porting to windows
I have a total of 85 patches to port elfutils to windows. I will post them all here, once I get around to write all the ChangeLog entries, but I'm fairly sure you won't like all of them. You can see them all (and also comment if you like) on the qt code review system. See https://codereview.qt-project.org/#/q/status:open+project:qt-creator/elfutils+branch:master,n,z . I might push some of them into my elfutils fork, though. Then they're not "open" anymore. br, Ulf
[PATCH] Add missing entries to .gitignore
Signed-off-by: Ulf Hermann --- .gitignore | 2 ++ ChangeLog | 4 2 files changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 0ee3af7..43a8d6e 100644 --- a/.gitignore +++ b/.gitignore @@ -123,6 +123,7 @@ Makefile.in /tests/elfstrmerge /tests/elfstrtab /tests/emptyfile +/tests/fillfile /tests/find-prologues /tests/funcretval /tests/funcscopes @@ -139,6 +140,7 @@ Makefile.in /tests/newdata /tests/newfile /tests/newscn +/tests/peel_type /tests/rdwrmmap /tests/rerequest_tag /tests/saridx diff --git a/ChangeLog b/ChangeLog index 48185c3..735a335 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-04-21 Ulf Hermann + + * .gitignore: Add fillfile and peel_type tests. + 2017-02-15 Ulf Hermann * configure.ac: Add check for mempcpy. -- 2.1.4
Re: porting to windows
Hi, I just tried to post the patch that adds all the gnulib modules. I suspect the mailing list doesn't like it because it's 4.8MB of diff. I've merged all the single "add xyz gnulib module" patches into one because you cannot sensibly reorder or skip any of them anyway. gnulib likes to keep several configuration files that change with every added module and trying to handle this using git results in lots of conflicts. I can, of course, change the selection of gnulib modules if necessary. This is the change I tried to post: https://codereview.qt-project.org/#/c/186564/ br, Ulf
Re: [PATCH v2] Add frame pointer unwinding for aarch64
On 04/24/2017 04:53 PM, Mark Wielaard wrote: > I got these separately. I assume they are as in the email you sent on > Mon, 10 Apr 2017 14:48:06 +0200 (which didn't hit the list because it > had the binaries attached...) Yes. Those are the right binaries. > This description doesn't seem to match anymore. Should this be: > > # The binary is generated by compiling with eh_frame CFI, but with frame > # pointers. > # > # gcc -static -O2 -fno-omit-frame-pointer -fno-asynchronous-unwind-tables \ > # -D_GNU_SOURCE -pthread -o tests/backtrace.x86_64.fp.exec -I. -Ilib \ > # tests/backtrace-child.c Almost right. It's backtrace.aarch64.fp.exec. Thanks for taking care of this, Ulf
Re: [PATCH 1/5] Revert "Optionally allow unknown symbols in the backtrace tests"
On 04/25/2017 02:49 PM, Mark Wielaard wrote: > This reverts commit f9971cb422df39adea7e8c7e22689b879e39c626. > > Allowing no symbol resolving at all makes it too hard to see > whether the test actually tests anything. > [...] Looks good to me. Ulf
Re: [PATCH 2/5] tests: Add core backtracegen chec and regenerate ppc32 backtrace test files.
On 04/25/2017 02:49 PM, Mark Wielaard wrote: > Add a check to check_core to make sure the backtracegen function is > found in the backtrace. This function is in the middle of the backtrace > in the main executable and if not found it means the backtrace was > incomplete or the frame was skipped (which could happen on a bad frame > pointer only unwind). > > This showed that the ppc32 backtrace test files were missing DWARF CFI > for the main executable. Regenerated them to include full CFI. Looks good to me. Ulf
Re: [PATCH 3/5] Add frame pointer unwinding as fallback on x86_64
On 04/25/2017 02:49 PM, Mark Wielaard wrote: > From: Ulf Hermann > > If we don't find any debug information for a given frame, we usually > cannot unwind any further. However, the binary in question might have > been compiled with frame pointers, in which case we can look up the > well known frame pointer locations in the stack snapshot and use them > to bridge the frames without debug information. > > The "unwind" hook is the right place for this as it is so far only > used on s390 and called only after trying to unwind with debug > information. Looks good to me. Ulf
Re: [PATCH 4/5] Add i386 frame pointer unwinder.
On 04/25/2017 02:49 PM, Mark Wielaard wrote: > Add a simple i386_unwind.c frame pointer unwinder as fallback if DWARF/CFI > unwinding fails. Looks good to me. The logic could be relaxed a bit so that failure to e.g. write the new value for sp would not be fatal. Then we might be able to unwind even more frames. But refusing to unwind obviously broken frames is acceptable, too. Ulf
Re: [PATCH 5/5] Add frame pointer unwinding for aarch64
On 04/25/2017 02:49 PM, Mark Wielaard wrote: > From: Ulf Hermann > > If we don't find any debug information for a given frame, we usually > cannot unwind any further. However, the binary in question might have > been compiled with frame pointers, in which case we can look up the > well known frame pointer locations in the stack snapshot and use them > to bridge the frames without debug information. Looks good to me. > +# The binary is generated by compiling with eh_frame CFI, but with frame > +# pointers. > +# > +# gcc -static -O2 -fno-omit-frame-pointer -fno-asynchronous-unwind-tables \ > +# -D_GNU_SOURCE -pthread -o tests/backtrace.aarch64.fp.exec -I. -Ilib \ > +# tests/backtrace-child.c# Trailing '#', but that is insignificant. Ulf
Re: [PATCH 5/5] Add frame pointer unwinding for aarch64
> My question is about this "initial frame". In our testcase we don't have > this case since the backtrace starts in a function that has some CFI. > But I assume you have some tests that rely on this behavior. Actually the test I provided does exercise this code. The initial __libc_do_syscall() frame does not have CFI. Only raise() has. You can check that by dropping the code for pc & 0x1. > The first question is how/why the (pc & 0x1) == 0 check works? > Why is that the correct check? > > Secondly, if it really is the initial (or signal frame) we are after, > should we pass in into bool *signal_framep argument. Currently we don't We have this piece of code in __libdwfl_frame_unwind, in frame_unwind.c: if (! state->initial_frame && ! state->signal_frame) pc--; AArch64 has a fixed instruction width of 32bit. So, normally the pc is aligned to 4 bytes. Except if we decrement it, then we are guaranteed to have an odd number, which we can then test to see if the frame in question is the initial or a signal frame. Of course it would be nicer to pass this information directly, but the signal_frame parameter is supposed to be an output parameter. After all we do the following after calling ebl_unwind(): state->unwound->signal_frame = signal_frame; > Lastly could you instead of returning the frame itself with just the pc > adjusted do that directly? > > if ((pc & 0x1) == 0) > lr = lr & (~0x1); If I dig up the first frame after the initial one from the stack, then we drop whatever we initially had in LR. Apparently, on aarch64 PC is always one frame "ahead" of the other registers. To establish that, we have to set PC to the value of LR on the initial frame, without actually unwinding. br, Ulf
Re: frame unwinding patches
> I dropped the arm32 frame pointer unwinder for now (maybe we need a less > demanding testcase for that or, more awesome, add code to translate the > exidx section for that). Another problem is that QV4-generated code on a new frame pushes LR first and then FP. Code generated by gcc with "-arm -mapcs-frame -fno-omit-frame-pointer" pushes FP first and then LR. The libc raise() I have here miraculously does the same as QV4. Also, QV4 can alternatively use either r11 or r7 for LR, depending on if we're in ARM or THUMB mode (which I cannot detect in the unwind hook). As that is written somewhere in AAPCS, I guess you can coax gcc to do the same thing (but just leaving out the "-arm" above simply leads to no frame pointers at all). Well, let's forget about this for now. I'll keep something that works with QV4 in ARM mode and ignore everything else. Ulf
Re: [PATCH 5/5] Add frame pointer unwinding for aarch64
On 04/26/2017 04:33 PM, Mark Wielaard wrote: > On Tue, 2017-04-25 at 15:38 +0200, Ulf Hermann wrote: >>> My question is about this "initial frame". In our testcase we don't have >>> this case since the backtrace starts in a function that has some CFI. >>> But I assume you have some tests that rely on this behavior. >> >> Actually the test I provided does exercise this code. The initial >> __libc_do_syscall() frame does not have CFI. Only raise() has. You can >> check that by dropping the code for pc & 0x1. > > Maybe I am using the wrong binaries (exec and core), but for me there is > no difference. In fact, with the new binaries there is no difference. I was confused, sorry. However, if you strip .eh_frame and .eh_frame_hdr from the exe (thus triggering the fp unwinding on the first frame), you will see that it skips sigusr2. At the same time it invents another frame 0x403f40 on the main thread. Apparently pthread_join creates two stack frames. As it correctly unwinds the rest, the latter seemed harmless to me. With .eh_frame and .eh_frame_hdr: ulf@zebra:~/dev/build-elfutils/tests$ ./backtrace --core=backtrace.aarch64.fp.core -e backtrace.aarch64.fp.exec 0x400x4a3000/home/ulf/backtrace.aarch64.fp.exec 0x7fb6380x7fb6381000linux-vdso.so.1 TID 350: # 0 0x40583craise # 1 0x401aac - 1sigusr2 # 2 0x401ba8 - 1stdarg # 3 0x401c04 - 1backtracegen # 4 0x401c10 - 1start # 5 0x402f44 - 1start_thread # 6 0x41dc70 - 1__clone TID 349: # 0 0x403fccpthread_join # 1 0x401810 - 1main # 2 0x406544 - 1__libc_start_main # 3 0x401918 - 1$x ./backtrace: dwfl_thread_getframes: address out of range Without .eh_frame and .eh_frame_hdr, code from PATCH V2: ulf@zebra:~/dev/build-elfutils/tests$ ./backtrace --core=backtrace.aarch64.fp.core -e backtrace.aarch64.fp.stripped 0x400x4a3000/home/ulf/backtrace.aarch64.fp.exec 0x7fb6380x7fb6381000linux-vdso.so.1 TID 350: # 0 0x40583c(null) # 1 0x401aac - 1(null) # 2 0x401ba8 - 1(null) # 3 0x401c04 - 1(null) # 4 0x401c10 - 1(null) # 5 0x402f44 - 1(null) # 6 0x41dc70 - 1(null) ./backtrace: dwfl_thread_getframes: address out of range TID 349: # 0 0x403fcc(null) # 1 0x403f40 - 1(null) # 2 0x401810 - 1(null) # 3 0x406544 - 1(null) # 4 0x401918 - 1(null) ./backtrace: dwfl_thread_getframes: address out of range Without .eh_frame and .eh_frame_hdr, without initial frame adjustment: ulf@zebra:~/dev/build-elfutils/tests$ ./backtrace --core=backtrace.aarch64.fp.core -e backtrace.aarch64.fp.stripped 0x400x4a3000/home/ulf/backtrace.aarch64.fp.exec 0x7fb6380x7fb6381000linux-vdso.so.1 TID 350: # 0 0x40583c(null) # 1 0x401ba8 - 1(null) # 2 0x401c04 - 1(null) # 3 0x401c10 - 1(null) # 4 0x402f44 - 1(null) # 5 0x41dc70 - 1(null) ./backtrace: dwfl_thread_getframes: address out of range TID 349: # 0 0x403fcc(null) # 1 0x401810 - 1(null) # 2 0x406544 - 1(null) # 3 0x401918 - 1(null) ./backtrace: dwfl_thread_getframes: address out of range You have to drop all the asserts from backtrace.c to actually test this: diff --git a/tests/backtrace.c b/tests/backtrace.c index 1ff6353..a910a77 100644 --- a/tests/backtrace.c +++ b/tests/backtrace.c @@ -71,14 +71,14 @@ static void callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc, const char *symname, Dwfl *dwfl) { - static bool seen_main = false; +// static bool seen_main = false; if (symname && *symname == '.') symname++; - if (symname && strcmp (symname, "main") == 0) -seen_main = true; +// if (symname && strcmp (symname, "main") == 0) +//seen_main = true; if (pc == 0) { - assert (seen_main); +// assert (seen_main); return; } if (check_tid == 0) @@ -103,11 +103,11 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc, && (strcmp (symname, "__kernel_vsyscall") == 0 || strcmp (symname, "__libc_do_syscall") == 0)) reduce_frameno = true; - else - assert (symname && strcmp (symname, "raise") == 0); +// else +// assert (symname && strcmp (symname, "raise") == 0); break; case 1: - assert (symname != NULL && strcmp (symname, "sigusr2") == 0); +// assert (symname != NULL && strcmp (symname, "sigusr2") == 0); break; case 2: // x86_64 only /* __restore_rt - glibc maybe does not have to have this symbol. */ @@ -125,11 +125,11 @@ callback_verify (pid_t tid, unsign
Re: [PATCH 5/5] Add frame pointer unwinding for aarch64
Maybe something like the attached patch? Well that's actually the original patch (as opposed to V2) with relaxed test conditions. You can write that a bit nicer by setting the new PC directly after retrieving LR and returning early if it doesn't work. See "[PATCH 2/3] Add frame pointer unwinding as fallback on arm" from February 16th. That's the original algorithm; for aarch64 I just added a few defines and included arm_unwind.c. It's in fact a bit annoying for my use case as the non-CFI stack sections are mostly in between CFI-enabled stack sections here. However, I can accept this. cheers, Ulf
Re: [PATCH 5/5] Add frame pointer unwinding for aarch64
Does every fp-only frame gets duplicated after a DWARF CFI frame? I'll look if I can better understand why that is. The last thing I've tested on an actual aarch64 setup is what I'm removing in this change: https://codereview.qt-project.org/#/c/191650/5/3rdparty/elfutils/backends/aarch64_unwind.c As you can see, I'm setting PC to the thing I read from memory, not the value of the LR register. So I must have had the same problem when I wrote that. Ulf
[PATCH] Fix nesting of braces
The way it was before it didn't actually test if elf_update failed, but rather did something random. !!() is a boolean and boolean true can be represented as anything non-0, including negative numbers. Signed-off-by: Ulf Hermann --- libasm/ChangeLog | 4 libasm/asm_end.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libasm/ChangeLog b/libasm/ChangeLog index 1656842..d2bc408 100644 --- a/libasm/ChangeLog +++ b/libasm/ChangeLog @@ -1,3 +1,7 @@ +2017-04-27 Ulf Hermann + + * asm_end.c (binary_end): Fix nesting of braces. + 2017-02-12 Mark Wielaard * asm_newsym.c (asm_newsym): Increase TEMPSYMLEN to 13. diff --git a/libasm/asm_end.c b/libasm/asm_end.c index 191a535..ced24f5 100644 --- a/libasm/asm_end.c +++ b/libasm/asm_end.c @@ -464,7 +464,7 @@ binary_end (AsmCtx_t *ctx) gelf_update_ehdr (ctx->out.elf, ehdr); /* Write out the ELF file. */ - if (unlikely (elf_update (ctx->out.elf, ELF_C_WRITE_MMAP)) < 0) + if (unlikely (elf_update (ctx->out.elf, ELF_C_WRITE_MMAP) < 0)) { __libasm_seterrno (ASM_E_LIBELF); result = -1; -- 2.8.1.windows.1
[PATCH] Drop handrolled or #ifdef'ed libc replacements
mempcpy, memrchr, rawmemchr, and argp are provided by gnulib now. We don't need to define them locally and we don't need to search for an external libargp. Signed-off-by: Ulf Hermann --- ChangeLog | 4 configure.ac | 31 --- lib/ChangeLog | 5 + lib/system.h | 5 - lib/xstrndup.c | 2 +- libasm/ChangeLog | 4 libasm/disasm_str.c| 2 +- libdw/ChangeLog| 4 libdw/Makefile.am | 2 +- libdwfl/ChangeLog | 4 libdwfl/linux-kernel-modules.c | 1 - libebl/ChangeLog | 5 + libebl/eblmachineflagname.c| 1 - libebl/eblopenbackend.c| 1 - libelf/ChangeLog | 5 + libelf/elf_getarsym.c | 8 libelf/elf_strptr.c| 11 --- src/ChangeLog | 4 src/Makefile.am| 30 +++--- tests/ChangeLog| 5 + tests/Makefile.am | 32 tests/elfstrmerge.c| 1 - 22 files changed, 74 insertions(+), 93 deletions(-) diff --git a/ChangeLog b/ChangeLog index a2a0f63..6fe525c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-04-27 Ulf Hermann + + * configure.ac: Drop checks for memrchr, rawmemchr, mempcpy, argp. + 2017-04-21 Ulf Hermann * .gitignore: Add generated gnulib headers. diff --git a/configure.ac b/configure.ac index a5aea7f..a48b13e 100644 --- a/configure.ac +++ b/configure.ac @@ -290,13 +290,7 @@ zip_LIBS="$LIBS" LIBS="$save_LIBS" AC_SUBST([zip_LIBS]) -AC_CHECK_DECLS([memrchr, rawmemchr],[],[], - [#define _GNU_SOURCE -#include ]) AC_CHECK_DECLS([powerof2],[],[],[#include ]) -AC_CHECK_DECLS([mempcpy],[],[], - [#define _GNU_SOURCE -#include ]) AC_CHECK_LIB([stdc++], [__cxa_demangle], [dnl AC_DEFINE([USE_DEMANGLE], [1], [Defined if demangling is enabled])]) @@ -369,31 +363,6 @@ CFLAGS="$old_CFLAGS"]) AM_CONDITIONAL(HAVE_IMPLICIT_FALLTHROUGH_WARNING, [test "x$ac_cv_implicit_fallthrough" != "xno"]) -dnl Check if we have argp available from our libc -AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [#include ], - [int argc=1; char *argv[]={"test"}; argp_parse(0,argc,&argv,0,0,0); return 0;] - )], - [libc_has_argp="true"], - [libc_has_argp="false"] -) - -dnl If our libc doesn't provide argp, then test for libargp -if test "$libc_has_argp" = "false" ; then - AC_MSG_WARN("libc does not have argp") - AC_CHECK_LIB([argp], [argp_parse], [have_argp="true"], [have_argp="false"]) - - if test "$have_argp" = "false"; then - AC_MSG_ERROR("no libargp found") - else - argp_LDADD="-largp" - fi -else - argp_LDADD="" -fi -AC_SUBST([argp_LDADD]) - dnl Check if we have for EM_BPF disassembly. AC_CHECK_HEADERS(linux/bpf.h) AM_CONDITIONAL(HAVE_LINUX_BPF_H, [test "x$ac_cv_header_linux_bpf_h" = "xyes"]) diff --git a/lib/ChangeLog b/lib/ChangeLog index 8cac7af..82c009e 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,8 @@ +2017-04-27 Ulf Hermann + + * system.h: Drop mempcpy replacement. + * xstrndup.c: Don't include system.h. + 2017-04-20 Ulf Hermann * crc32.c: include config.h. diff --git a/lib/system.h b/lib/system.h index 9203335..ffa2bc7 100644 --- a/lib/system.h +++ b/lib/system.h @@ -63,11 +63,6 @@ #define powerof2(x) (((x) & ((x) - 1)) == 0) #endif -#if !HAVE_DECL_MEMPCPY -#define mempcpy(dest, src, n) \ -((void *) ((char *) memcpy (dest, src, n) + (size_t) n)) -#endif - /* A special gettext function we use if the strings are too short. */ #define sgettext(Str) \ ({ const char *__res = strrchr (gettext (Str), '|'); \ diff --git a/lib/xstrndup.c b/lib/xstrndup.c index a257aa9..d43e3b9 100644 --- a/lib/xstrndup.c +++ b/lib/xstrndup.c @@ -33,7 +33,7 @@ #include #include #include "libeu.h" -#include "system.h" + /* Return a newly allocated copy of STRING. */ char * diff --git a/libasm/ChangeLog b/libasm/ChangeLog index ef183a6..80aa7de 100644 --- a/libasm/ChangeLog +++ b/libasm/ChangeLog @@ -1,3 +1,7 @@ +2017-02-27 Ulf Hermann + + * disasm_str.c: Don't include system.h + 2017-02-21 Ulf Hermann * Makefile.am: Link libasm agaist libgnu.a if requested. diff --git a/libasm/disasm_str.c b/libasm/disasm_str.c index c14e6d5..5b0bb29 100644 --- a/libasm/disasm_str.c +++ b/libasm/disasm_str.c @@ -31,7 +31,7 @@ #endif #
[PATCH] Check for -z,defs, -z,relro, -fPIC, -fPIE before using them
On windows those aren't needed because the link results are no ELF files and all code is position independent anyway. gcc then complains about them, which is in turn caught by -Werror. Signed-off-by: Ulf Hermann --- ChangeLog| 5 + backends/ChangeLog | 4 backends/Makefile.am | 4 ++-- config/ChangeLog | 4 config/eu.am | 4 ++-- configure.ac | 56 ++-- lib/ChangeLog| 4 lib/Makefile.am | 2 +- libasm/ChangeLog | 4 libasm/Makefile.am | 2 +- libcpu/ChangeLog | 4 libcpu/Makefile.am | 2 +- libdw/ChangeLog | 4 libdw/Makefile.am| 4 ++-- libebl/ChangeLog | 4 libebl/Makefile.am | 2 +- libelf/ChangeLog | 4 libelf/Makefile.am | 6 +++--- libgnu/Makefile.am | 2 +- tests/ChangeLog | 4 tests/Makefile.am| 4 ++-- 21 files changed, 111 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6fe525c..36c3cc7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2017-04-27 Ulf Hermann + * configure.ac: Check if -fPIC, -fPIE, -Wl,-z,defs, + and -Wl,-z,relro are supported by the compiler. + +2017-04-27 Ulf Hermann + * configure.ac: Drop checks for memrchr, rawmemchr, mempcpy, argp. 2017-04-21 Ulf Hermann diff --git a/backends/ChangeLog b/backends/ChangeLog index 594aa98..baeb7b9 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,7 @@ +2017-04-27 Ulf Hermann + + * Makefile.am: Use dso_LDFLAGS. + 2017-04-21 Ulf Hermann * Makefile.am: Link backends against libgnu.a if requested. diff --git a/backends/Makefile.am b/backends/Makefile.am index 5dcb3e1..3e1992e 100644 --- a/backends/Makefile.am +++ b/backends/Makefile.am @@ -138,10 +138,10 @@ libebl_%.so libebl_%.map: libebl_%_pic.a $(libelf) $(libdw) $(libgnu) @rm -f $(@:.so=.map) $(AM_V_at)echo 'ELFUTILS_$(PACKAGE_VERSION) { global: $*_init; local: *; };' \ > $(@:.so=.map) - $(AM_V_CCLD)$(LINK) -shared -o $(@:.map=.so) \ + $(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $(@:.map=.so) \ -Wl,--whole-archive $< $(cpu_$*) -Wl,--no-whole-archive \ -Wl,--version-script,$(@:.so=.map) \ - -Wl,-z,defs -Wl,--as-needed $(libelf) $(libdw) $(libgnu) + -Wl,--as-needed $(libelf) $(libdw) $(libgnu) @$(textrel_check) libebl_i386.so: $(cpu_i386) diff --git a/config/ChangeLog b/config/ChangeLog index 756bab6..59569e3 100644 --- a/config/ChangeLog +++ b/config/ChangeLog @@ -1,3 +1,7 @@ +2017-04-27 Ulf Hermann + + * eu.am: Use fpic_CFLAGS. + 2017-04-21 Ulf Hermann * eu.am: Add $(top_srcdir)libgnu and $(top_builddir)/libgnu to -I if requested. diff --git a/config/eu.am b/config/eu.am index 11c2fec..bc8c767 100644 --- a/config/eu.am +++ b/config/eu.am @@ -89,14 +89,14 @@ endif %.os: %.c %.o if AMDEP - $(AM_V_CC)if $(COMPILE.os) -c -o $@ -fPIC $(DEFS.os) -MT $@ -MD -MP \ + $(AM_V_CC)if $(COMPILE.os) -c -o $@ $(fpic_CFLAGS) $(DEFS.os) -MT $@ -MD -MP \ -MF "$(DEPDIR)/$*.Tpo" `test -f '$<' || echo '$(srcdir)/'`$<; \ then cat "$(DEPDIR)/$*.Tpo" >> "$(DEPDIR)/$*.Po"; \ rm -f "$(DEPDIR)/$*.Tpo"; \ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \ fi else - $(AM_V_CC)$(COMPILE.os) -c -o $@ -fPIC $(DEFS.os) $< + $(AM_V_CC)$(COMPILE.os) -c -o $@ $(fpic_CFLAGS) $(DEFS.os) $< endif CLEANFILES = *.gcno *.gcda diff --git a/configure.ac b/configure.ac index a48b13e..107762f 100644 --- a/configure.ac +++ b/configure.ac @@ -136,13 +136,65 @@ CFLAGS="$old_CFLAGS"]) AS_IF([test "x$ac_cv_c99" != xyes], AC_MSG_ERROR([gcc with GNU99 support required])) +AC_CACHE_CHECK([whether gcc supports -fPIC], ac_cv_fpic, [dnl +save_CFLAGS="$CFLAGS" +CFLAGS="$save_CFLAGS -fPIC -Werror" +AC_COMPILE_IFELSE([AC_LANG_SOURCE()], ac_cv_fpic=yes, ac_cv_fpic=no) +CFLAGS="$save_CFLAGS" +]) +if test "$ac_cv_fpic" = "yes"; then + fpic_CFLAGS="-fPIC" +else + fpic_CFLAGS="" +fi +AC_SUBST([fpic_CFLAGS]) + +AC_CACHE_CHECK([whether gcc supports -fPIE], ac_cv_fpie, [dnl +save_CFLAGS="$CFLAGS" +CFLAGS="$save_CFLAGS -fPIE -Werror" +AC_COMPILE_IFELSE([AC_LANG_SOURCE()], ac_cv_fpie=yes, ac_cv_fpie=no) +CFLAGS="$save_CFLAGS" +]) +if test "$ac_cv_fpie" = "yes"; then + fpie_CFLAGS="-fPIE" +else + fpie_CFLAGS="" +fi +AC_SUBST([fpie_CFLAGS]) + +dso_LDFLAGS="-shared" + +ZDEFS_LDFLAGS="-Wl,-z,defs" +AC_CACHE_CHECK([whether gcc supports $ZDEFS_LDFLAGS], ac_cv_zdefs, [dnl +save_LDFLAGS="$LDFLAGS" +LDFLAGS="$ZDEFS_LDFLAGS $save_LDF
[PATCH v2] Check for -z,defs, -z,relro, -fPIC, -fPIE before using them
On windows those aren't needed because the link results are no ELF files and all code is position independent anyway. gcc then complains about them, which is in turn caught by -Werror. Signed-off-by: Ulf Hermann --- ChangeLog| 5 + backends/ChangeLog | 4 backends/Makefile.am | 4 ++-- config/ChangeLog | 4 config/eu.am | 4 ++-- configure.ac | 56 ++-- lib/ChangeLog| 4 lib/Makefile.am | 2 +- libasm/ChangeLog | 4 libasm/Makefile.am | 2 +- libcpu/ChangeLog | 4 libcpu/Makefile.am | 2 +- libdw/ChangeLog | 4 libdw/Makefile.am| 4 ++-- libebl/ChangeLog | 4 libebl/Makefile.am | 2 +- libelf/ChangeLog | 4 libelf/Makefile.am | 6 +++--- libgnu/Makefile.am | 2 +- tests/ChangeLog | 4 tests/Makefile.am| 4 ++-- 21 files changed, 111 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6fe525c..36c3cc7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2017-04-27 Ulf Hermann + * configure.ac: Check if -fPIC, -fPIE, -Wl,-z,defs, + and -Wl,-z,relro are supported by the compiler. + +2017-04-27 Ulf Hermann + * configure.ac: Drop checks for memrchr, rawmemchr, mempcpy, argp. 2017-04-21 Ulf Hermann diff --git a/backends/ChangeLog b/backends/ChangeLog index 594aa98..baeb7b9 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,7 @@ +2017-04-27 Ulf Hermann + + * Makefile.am: Use dso_LDFLAGS. + 2017-04-21 Ulf Hermann * Makefile.am: Link backends against libgnu.a if requested. diff --git a/backends/Makefile.am b/backends/Makefile.am index 5dcb3e1..3e1992e 100644 --- a/backends/Makefile.am +++ b/backends/Makefile.am @@ -138,10 +138,10 @@ libebl_%.so libebl_%.map: libebl_%_pic.a $(libelf) $(libdw) $(libgnu) @rm -f $(@:.so=.map) $(AM_V_at)echo 'ELFUTILS_$(PACKAGE_VERSION) { global: $*_init; local: *; };' \ > $(@:.so=.map) - $(AM_V_CCLD)$(LINK) -shared -o $(@:.map=.so) \ + $(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $(@:.map=.so) \ -Wl,--whole-archive $< $(cpu_$*) -Wl,--no-whole-archive \ -Wl,--version-script,$(@:.so=.map) \ - -Wl,-z,defs -Wl,--as-needed $(libelf) $(libdw) $(libgnu) + -Wl,--as-needed $(libelf) $(libdw) $(libgnu) @$(textrel_check) libebl_i386.so: $(cpu_i386) diff --git a/config/ChangeLog b/config/ChangeLog index 756bab6..59569e3 100644 --- a/config/ChangeLog +++ b/config/ChangeLog @@ -1,3 +1,7 @@ +2017-04-27 Ulf Hermann + + * eu.am: Use fpic_CFLAGS. + 2017-04-21 Ulf Hermann * eu.am: Add $(top_srcdir)libgnu and $(top_builddir)/libgnu to -I if requested. diff --git a/config/eu.am b/config/eu.am index 11c2fec..bc8c767 100644 --- a/config/eu.am +++ b/config/eu.am @@ -89,14 +89,14 @@ endif %.os: %.c %.o if AMDEP - $(AM_V_CC)if $(COMPILE.os) -c -o $@ -fPIC $(DEFS.os) -MT $@ -MD -MP \ + $(AM_V_CC)if $(COMPILE.os) -c -o $@ $(fpic_CFLAGS) $(DEFS.os) -MT $@ -MD -MP \ -MF "$(DEPDIR)/$*.Tpo" `test -f '$<' || echo '$(srcdir)/'`$<; \ then cat "$(DEPDIR)/$*.Tpo" >> "$(DEPDIR)/$*.Po"; \ rm -f "$(DEPDIR)/$*.Tpo"; \ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \ fi else - $(AM_V_CC)$(COMPILE.os) -c -o $@ -fPIC $(DEFS.os) $< + $(AM_V_CC)$(COMPILE.os) -c -o $@ $(fpic_CFLAGS) $(DEFS.os) $< endif CLEANFILES = *.gcno *.gcda diff --git a/configure.ac b/configure.ac index a48b13e..107762f 100644 --- a/configure.ac +++ b/configure.ac @@ -136,13 +136,65 @@ CFLAGS="$old_CFLAGS"]) AS_IF([test "x$ac_cv_c99" != xyes], AC_MSG_ERROR([gcc with GNU99 support required])) +AC_CACHE_CHECK([whether gcc supports -fPIC], ac_cv_fpic, [dnl +save_CFLAGS="$CFLAGS" +CFLAGS="$save_CFLAGS -fPIC -Werror" +AC_COMPILE_IFELSE([AC_LANG_SOURCE()], ac_cv_fpic=yes, ac_cv_fpic=no) +CFLAGS="$save_CFLAGS" +]) +if test "$ac_cv_fpic" = "yes"; then + fpic_CFLAGS="-fPIC" +else + fpic_CFLAGS="" +fi +AC_SUBST([fpic_CFLAGS]) + +AC_CACHE_CHECK([whether gcc supports -fPIE], ac_cv_fpie, [dnl +save_CFLAGS="$CFLAGS" +CFLAGS="$save_CFLAGS -fPIE -Werror" +AC_COMPILE_IFELSE([AC_LANG_SOURCE()], ac_cv_fpie=yes, ac_cv_fpie=no) +CFLAGS="$save_CFLAGS" +]) +if test "$ac_cv_fpie" = "yes"; then + fpie_CFLAGS="-fPIE" +else + fpie_CFLAGS="" +fi +AC_SUBST([fpie_CFLAGS]) + +dso_LDFLAGS="-shared" + +ZDEFS_LDFLAGS="-Wl,-z,defs" +AC_CACHE_CHECK([whether gcc supports $ZDEFS_LDFLAGS], ac_cv_zdefs, [dnl +save_LDFLAGS="$LDFLAGS" +LDFLAGS="$ZDEFS_LDFLAGS $save_LDF
[PATCH] Check if gcc complains about __attribute__ (visibility(..))
If so, define attribute_hidden to be empty. Also, use attribute_hidden in all places where we hide symbols. Change-Id: I37353459710dbbd1c6c6c46110514fc18515c814 Signed-off-by: Ulf Hermann --- ChangeLog | 5 + configure.ac| 16 lib/ChangeLog | 5 + lib/eu-config.h | 4 libdw/ChangeLog | 5 + libdw/libdwP.h | 2 +- libdw/libdw_alloc.c | 2 +- libelf/ChangeLog| 4 libelf/libelfP.h| 2 +- 9 files changed, 42 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 36c3cc7..01f88f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2017-04-27 Ulf Hermann + * configure.ac: Check if the compiler supports + __attribute__((visibility(...))). + +2017-04-27 Ulf Hermann + * configure.ac: Check if -fPIC, -fPIE, -Wl,-z,defs, and -Wl,-z,relro are supported by the compiler. diff --git a/configure.ac b/configure.ac index 107762f..165149d 100644 --- a/configure.ac +++ b/configure.ac @@ -136,6 +136,22 @@ CFLAGS="$old_CFLAGS"]) AS_IF([test "x$ac_cv_c99" != xyes], AC_MSG_ERROR([gcc with GNU99 support required])) +AC_CACHE_CHECK([whether gcc supports __attribute__((visibility()))], + ac_cv_visibility, [dnl +save_CFLAGS="$CFLAGS" +CFLAGS="$save_CFLAGS -Werror" +AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl +int __attribute__((visibility("hidden"))) +foo (int a) +{ + return a; +}])], ac_cv_visibility=yes, ac_cv_visibility=no) +CFLAGS="$save_CFLAGS"]) +if test "$ac_cv_visibility" = "yes"; then + AC_DEFINE([HAVE_VISIBILITY], [1], + [Defined if __attribute__((visibility())) is supported]) +fi + AC_CACHE_CHECK([whether gcc supports -fPIC], ac_cv_fpic, [dnl save_CFLAGS="$CFLAGS" CFLAGS="$save_CFLAGS -fPIC -Werror" diff --git a/lib/ChangeLog b/lib/ChangeLog index 605b9b9..ecc6179 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,5 +1,10 @@ 2017-04-27 Ulf Hermann + * eu-config.h: Define attribute_hidden to be empty if the compiler + doesn't support it. + +2017-04-27 Ulf Hermann + * Makefile.am: Use fpic_CFLAGS. 2017-04-27 Ulf Hermann diff --git a/lib/eu-config.h b/lib/eu-config.h index 400cdc6..0709828 100644 --- a/lib/eu-config.h +++ b/lib/eu-config.h @@ -68,8 +68,12 @@ #define internal_strong_alias(name, aliasname) \ extern __typeof (name) aliasname __attribute__ ((alias (#name))) internal_function; +#ifdef HAVE_VISIBILITY #define attribute_hidden \ __attribute__ ((visibility ("hidden"))) +#else +#define attribute_hidden /* empty */ +#endif /* Define ALLOW_UNALIGNED if the architecture allows operations on unaligned memory locations. */ diff --git a/libdw/ChangeLog b/libdw/ChangeLog index d15c861..79c3898 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,5 +1,10 @@ 2017-02-27 Ulf Hermann + * libdwP.h: Use attribute_hidden. + * libdw_alloc.c: Likewise. + +2017-02-27 Ulf Hermann + * Makefile.am: Use fpic_CFLAGS and dso_LDFLAGS. 2017-02-27 Ulf Hermann diff --git a/libdw/libdwP.h b/libdw/libdwP.h index 5d095a7..cefcafd 100644 --- a/libdw/libdwP.h +++ b/libdw/libdwP.h @@ -433,7 +433,7 @@ extern void *__libdw_allocate (Dwarf *dbg, size_t minsize, size_t align) __attribute__ ((__malloc__)) __nonnull_attribute__ (1); /* Default OOM handler. */ -extern void __libdw_oom (void) __attribute ((noreturn, visibility ("hidden"))); +extern void __libdw_oom (void) __attribute ((noreturn)) attribute_hidden; /* Allocate the internal data for a unit not seen before. */ extern struct Dwarf_CU *__libdw_intern_next_unit (Dwarf *dbg, bool debug_types) diff --git a/libdw/libdw_alloc.c b/libdw/libdw_alloc.c index 28a8cf6..d6af23a 100644 --- a/libdw/libdw_alloc.c +++ b/libdw/libdw_alloc.c @@ -70,7 +70,7 @@ dwarf_new_oom_handler (Dwarf *dbg, Dwarf_OOM handler) void -__attribute ((noreturn, visibility ("hidden"))) +__attribute ((noreturn)) attribute_hidden __libdw_oom (void) { while (1) diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 1c6cce2..fd58ed3 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,5 +1,9 @@ 2017-04-27 Ulf Hermann + * libelfP.h: Use attribute_hidden. + +2017-04-27 Ulf Hermann + * Makefile.am: Use fpic_CFLAGS and dso_LDFLAGS. 2017-04-27 Ulf Hermann diff --git a/libelf/libelfP.h b/libelf/libelfP.h index 7ee6625..a4a0a3a 100644 --- a/libelf/libelfP.h +++ b/libelf/libelfP.h @@ -578,7 +578,7 @@ extern Elf_Data *__elf64_xlatetof_internal (Elf_Data *__dest, extern unsigned int __elf_version_internal (unsigned int __version) attribute_hidden; extern unsigned long int __elf_hash_internal (const char *__string) - __attribute__ ((__pure__, visibility ("hidden"))); + __attribute__ ((__pure__)) attribute_hidden; extern long int __elf32_checksum_internal (Elf *__elf) attribute_hidden; extern long int __elf64_checksum_internal (Elf *__elf) attribute_hidden; -- 2.1.4
Re: [PATCH] Don't look for kernel version if not running on linux
On 04/27/2017 08:02 PM, Mark Wielaard wrote: > On Thu, Apr 20, 2017 at 04:08:48PM +0200, Ulf Hermann wrote: >> We don't want to use it, even if it exists. > > I am not sure this is really the right place to patch. > The value is retrieved through uname () which is POSIX and so should > be available even on non-GNU/Linux systems. When kernel_release () > returns NULL the callers expect errno to be set so they can use it > to return a failure code. You can get uname() on Windows through gnulib, but at the cost at linking to additional windows DLLs. It calls gethostname and for that we need to link against ws2_32.dll. That's an unreasonable dependency for getting something we cannot use anyway. I suggest we just set errno to ENOTSUP then. Ulf
Re: [PATCH] On elf_update, remember when we mmap()
On 04/28/2017 12:23 AM, Mark Wielaard wrote: > On Thu, Apr 20, 2017 at 04:57:41PM +0200, Ulf Hermann wrote: >> Otherwise we skip the munmap() later. This leaks resources. > > Oops. Good find. Applied to master. > > When configured --with-valgrind the tests are run under valgrind > and memory leaks will fail the tests. But since this is mmap > valgrind won't report it. How did you find it? On windows you cannot rename or unlink files if there are still open views on it (and the win32 view mechanism is how I implement mmap on windows). So, the test cases fail then because the directories are not empty. Ulf
Re: [PATCH] Make elf section sorting more deterministic
On 04/27/2017 09:41 PM, Mark Wielaard wrote: > On Thu, Apr 20, 2017 at 04:54:26PM +0200, Ulf Hermann wrote: >> At least one test (dwfl-addr-sect) depends on the order of elf sections >> with equal addresses. This is not guaranteed by the code. Compare also >> by end address and name to tell entries apart. > > O, interesting find. If the start addresses match the order depends on > the specific qsort algorithm. So you need a real tie breaker. > > I think it is simpler and more predictable if we just take the section > number into account. It seem to have the added benefit that it provide > the same ordering as before with the glibc qsort, so no testcases need > to be adjusted. Does the following work for you? > > diff --git a/libdwfl/derelocate.c b/libdwfl/derelocate.c > index 439a24e..0d10672 100644 > --- a/libdwfl/derelocate.c > +++ b/libdwfl/derelocate.c > @@ -63,7 +63,10 @@ compare_secrefs (const void *a, const void *b) >if ((*p1)->start > (*p2)->start) > return 1; > > - return 0; > + /* Same start address, then just compare which section came first. */ > + size_t n1 = elf_ndxscn ((*p1)->scn); > + size_t n2 = elf_ndxscn ((*p2)->scn); > + return n1 - n2; I would inline the whole thing to return elf_ndxscn (p1->scn) - elf_ndxscn (p2->scn); There is no point in forcing the compiler to keep the intermediate numbers as (signed) size_t. Also, I would still keep the check for p1->end and p2->end before this. If we have a section of size 0, and another one of size > 0 starting at the same place, we want them to be sorted by end address. The zero-sized section should be squeezed in before the one that actually has a size, not after it. Ulf
[PATCH] Check if we need -lintl for linking gettext
We might not have gettext available from libc and we cannot get it from gnulib either. Signed-off-by: Ulf Hermann --- ChangeLog| 5 + backends/ChangeLog | 4 backends/Makefile.am | 2 +- configure.ac | 25 + libasm/ChangeLog | 4 libasm/Makefile.am | 2 +- libcpu/ChangeLog | 4 libcpu/Makefile.am | 2 +- libdw/ChangeLog | 4 libdw/Makefile.am| 2 +- libelf/ChangeLog | 4 libelf/Makefile.am | 2 +- src/ChangeLog| 4 src/Makefile.am | 30 +++--- tests/ChangeLog | 4 tests/Makefile.am| 18 +- 16 files changed, 87 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 01f88f3..ccfb3ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-04-28 Ulf Hermann + + * configure.ac: Check for availability of dgettext from either libc or + a separate libintl. + 2017-04-27 Ulf Hermann * configure.ac: Check if the compiler supports diff --git a/backends/ChangeLog b/backends/ChangeLog index baeb7b9..a35d83a 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,7 @@ +2017-04-28 Ulf Hermann + + * Makefile.am: Use intl_LDADD. + 2017-04-27 Ulf Hermann * Makefile.am: Use dso_LDFLAGS. diff --git a/backends/Makefile.am b/backends/Makefile.am index 3e1992e..6dc2022 100644 --- a/backends/Makefile.am +++ b/backends/Makefile.am @@ -141,7 +141,7 @@ libebl_%.so libebl_%.map: libebl_%_pic.a $(libelf) $(libdw) $(libgnu) $(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $(@:.map=.so) \ -Wl,--whole-archive $< $(cpu_$*) -Wl,--no-whole-archive \ -Wl,--version-script,$(@:.so=.map) \ - -Wl,--as-needed $(libelf) $(libdw) $(libgnu) + -Wl,--as-needed $(libelf) $(libdw) $(libgnu) $(intl_LDADD) @$(textrel_check) libebl_i386.so: $(cpu_i386) diff --git a/configure.ac b/configure.ac index 165149d..0266a36 100644 --- a/configure.ac +++ b/configure.ac @@ -431,6 +431,31 @@ CFLAGS="$old_CFLAGS"]) AM_CONDITIONAL(HAVE_IMPLICIT_FALLTHROUGH_WARNING, [test "x$ac_cv_implicit_fallthrough" != "xno"]) +dnl Check if gettext is available form libc +AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [#include ], + [dgettext("foo", "bar"); return 0;] + )], + [libc_has_gettext="true"], + [libc_has_gettext="false"] +) + +dnl If our libc doesn't provide gettext, then test for libintl +if test "$libc_has_gettext" = "false" ; then + AC_MSG_WARN("libc does not have gettext") + AC_CHECK_LIB([intl], [dgettext], [have_intl="true"], [have_intl="false"], [-liconv]) + + if test "$have_intl" = "false"; then + AC_MSG_ERROR("no libintl found") + else + intl_LDADD="-lintl -liconv" + fi +else + intl_LDADD="" +fi +AC_SUBST([intl_LDADD]) + dnl Check if we have for EM_BPF disassembly. AC_CHECK_HEADERS(linux/bpf.h) AM_CONDITIONAL(HAVE_LINUX_BPF_H, [test "x$ac_cv_header_linux_bpf_h" = "xyes"]) diff --git a/libasm/ChangeLog b/libasm/ChangeLog index 971492a..066c64e 100644 --- a/libasm/ChangeLog +++ b/libasm/ChangeLog @@ -1,3 +1,7 @@ +2017-02-28 Ulf Hermann + + * Makefile.am: Use intl_LDADD. + 2017-02-27 Ulf Hermann * Makefile.am: Use dso_LDFLAGS. diff --git a/libasm/Makefile.am b/libasm/Makefile.am index a5fc9fc..30f7fa9 100644 --- a/libasm/Makefile.am +++ b/libasm/Makefile.am @@ -55,7 +55,7 @@ libasm_a_SOURCES = asm_begin.c asm_abort.c asm_end.c asm_error.c \ libasm_pic_a_SOURCES = am_libasm_pic_a_OBJECTS = $(libasm_a_SOURCES:.c=.os) -libasm_so_LDLIBS = +libasm_so_LDLIBS = $(intl_LDADD) if USE_LOCKS libasm_so_LDLIBS += -lpthread endif diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog index ef5da58..42cfb58 100644 --- a/libcpu/ChangeLog +++ b/libcpu/ChangeLog @@ -1,3 +1,7 @@ +2017-02-28 Ulf Hermann + + * Makefile.am: Use intl_LDADD. + 2017-02-27 Ulf Hermann * Makefile.am: Use fpic_CFLAGS. diff --git a/libcpu/Makefile.am b/libcpu/Makefile.am index 9ca0f43..d277583 100644 --- a/libcpu/Makefile.am +++ b/libcpu/Makefile.am @@ -90,7 +90,7 @@ i386_lex_CFLAGS = -Wno-unused-label -Wno-unused-function -Wno-sign-compare i386_parse.o: i386_parse.c i386.mnemonics i386_parse_CFLAGS = -DNMNES="`wc -l < i386.mnemonics`" i386_lex.o: i386_parse.h -i386_gendis_LDADD = $(libeu) $(libgnu) -lm +i386_gendis_LDADD = $(libeu) $(libgnu) $(intl_LDADD) -lm i386_parse.h: i386_parse.c ; diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 79c3898..7c6e19a 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,7 @@ +2017-02-28 Ulf Hermann + + * Makefil
[PATCH] Disable symbol versioning if .symver doesn't work
Signed-off-by: Ulf Hermann --- ChangeLog| 5 + configure.ac | 12 2 files changed, 17 insertions(+) diff --git a/ChangeLog b/ChangeLog index 01f88f3..fb7317c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-04-28 Ulf Hermann + + * configure.ac: Test if symbol versioning is supported and + automatically disable it if not. + 2017-04-27 Ulf Hermann * configure.ac: Check if the compiler supports diff --git a/configure.ac b/configure.ac index 0266a36..efcd3c0 100644 --- a/configure.ac +++ b/configure.ac @@ -376,6 +376,18 @@ AS_IF([test "x$enable_textrelcheck" != "xno"], AC_ARG_ENABLE([symbol-versioning], AS_HELP_STRING([--disable-symbol-versioning], [Disable symbol versioning in shared objects])) + +AC_CACHE_CHECK([whether symbol versioning is supported], ac_cv_symbol_versioning, [dnl +AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl +#define NEW_VERSION(name, version) \ + asm (".symver " #name "," #name "@@@" #version); +int foo(int x) { return x + 1; } +NEW_VERSION (foo, ELFUTILS_12.12) +])], ac_cv_symbol_versioning=yes, ac_cv_symbol_versioning=no)]) +if test "$ac_cv_symbol_versioning" = "no"; then + enable_symbol_versioning=no +fi + AM_CONDITIONAL(SYMBOL_VERSIONING, [test "x$enable_symbol_versioning" != "xno"]) AS_IF([test "x$enable_symbol_versioning" = "xno"], [AC_MSG_WARN([Disabling symbol versioning breaks ABI compatibility.]) -- 2.1.4
[PATCH] Check if rpath is supported before setting it
Some systems don't have rpath. In that case the backends need to be made available by some external mechanism. Warn about it. Signed-off-by: Ulf Hermann --- ChangeLog | 5 + configure.ac | 12 libdw/ChangeLog | 5 + libdw/Makefile.am | 9 +++-- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 01f88f3..e5b74fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-04-28 Ulf Hermann + + * configure.ac: Check if the linker supports -rpath and output a + warning if it doesn't. + 2017-04-27 Ulf Hermann * configure.ac: Check if the compiler supports diff --git a/configure.ac b/configure.ac index efcd3c0..b943547 100644 --- a/configure.ac +++ b/configure.ac @@ -204,6 +204,18 @@ fi AC_SUBST([dso_LDFLAGS]) +AC_CACHE_CHECK([for rpath support], ac_cv_rpath, [dnl +save_LDFLAGS="$LDFLAGS" +LDFLAGS="$save_LDFLAGS -Wl,--enable-new-dtags,-rpath,/foo/bar" +AC_LINK_IFELSE([AC_LANG_PROGRAM()], ac_cv_rpath=yes, ac_cv_rpath=no) +LDFLAGS="$save_LDFLAGS" +]) +if test "$ac_cv_rpath" = "no"; then + AC_MSG_WARN([rpath is not supported. libdw will not automatically +find the ebl backends.]) +fi +AM_CONDITIONAL(RPATH, test "$ac_cv_rpath" = "yes") + AC_CACHE_CHECK([for __thread support], ac_cv_tls, [dnl # Use the same flags that we use for our DSOs, so the test is representative. # Some old compiler/linker/libc combinations fail some ways and not others. diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 79c3898..45303d6 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,8 @@ +2017-02-28 Ulf Hermann + + * Makefile.am: If the linker doesn't support -rpath, don't try to set + it. + 2017-02-27 Ulf Hermann * libdwP.h: Use attribute_hidden. diff --git a/libdw/Makefile.am b/libdw/Makefile.am index 31f7012..055e3f1 100644 --- a/libdw/Makefile.am +++ b/libdw/Makefile.am @@ -99,6 +99,12 @@ $(srcdir)/known-dwarf.h: $(top_srcdir)/config/known-dwarf.awk $(srcdir)/dwarf.h mv -f $@.new $@ endif +if RPATH +PKG_RPATH = -Wl,--enable-new-dtags,-rpath,$(pkglibdir) +else +PKG_RPATH = +endif + libdw_pic_a_SOURCES = am_libdw_pic_a_OBJECTS = $(libdw_a_SOURCES:.c=.os) @@ -115,8 +121,7 @@ libdw.so$(EXEEXT): $(srcdir)/libdw.map libdw_pic.a ../libdwelf/libdwelf_pic.a \ # The rpath is necessary for libebl because its $ORIGIN use will # not fly in a setuid executable that links in libdw. $(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ -Wl,--soname,$@.$(VERSION) \ - -Wl,--enable-new-dtags,-rpath,$(pkglibdir) \ - -Wl,--version-script,$<,--no-undefined \ + -Wl,--version-script,$<,--no-undefined $(PKG_RPATH) \ -Wl,--whole-archive $(filter-out $<,$^) -Wl,--no-whole-archive\ -ldl -lz $(intl_LDADD) $(zip_LIBS) $(libgnu) @$(textrel_check) -- 2.1.4
[PATCH] Generalize library names
On windows library names end with ".dll" and the prefix "lib" us usually omitted. Take this into account and also drop the $(EXEEXT) workaround. We don't need to use noinst_PROGRAMS as there is also noinst_DATA. Change-Id: I7e4ba2432811d5ad85051ea0c9d5674eabf79b3c Signed-off-by: Ulf Hermann --- ChangeLog | 5 + backends/ChangeLog | 5 + backends/Makefile.am| 33 + configure.ac| 30 ++ libasm/ChangeLog| 5 + libasm/Makefile.am | 28 +--- libdw/ChangeLog | 5 + libdw/Makefile.am | 28 +--- libebl/ChangeLog| 6 ++ libebl/Makefile.am | 2 ++ libebl/eblopenbackend.c | 9 + libelf/ChangeLog| 5 + libelf/Makefile.am | 26 -- m4/ChangeLog| 4 m4/libname.m4 | 38 ++ src/ChangeLog | 5 + src/Makefile.am | 6 +++--- tests/ChangeLog | 8 tests/Makefile.am | 22 +- tests/run-deleted.sh| 8 +--- 20 files changed, 199 insertions(+), 79 deletions(-) create mode 100644 m4/libname.m4 diff --git a/ChangeLog b/ChangeLog index 01f88f3..3613beb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-04-28 Ulf Hermann + + * configure.ac: Determine library naming conventions and define + LIBPREFIX, LIBEXT and common names for elf, dw, asm accordingly. + 2017-04-27 Ulf Hermann * configure.ac: Check if the compiler supports diff --git a/backends/ChangeLog b/backends/ChangeLog index baeb7b9..e2f0529 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,8 @@ +2017-04-28 Ulf Hermann + + * Makefile.am: Have the backend file names follow the platform's + convention for naming shared libraries. + 2017-04-27 Ulf Hermann * Makefile.am: Use dso_LDFLAGS. diff --git a/backends/Makefile.am b/backends/Makefile.am index 6dc2022..55ff871 100644 --- a/backends/Makefile.am +++ b/backends/Makefile.am @@ -40,11 +40,12 @@ libebl_pic = libebl_i386_pic.a libebl_sh_pic.a libebl_x86_64_pic.a\ libebl_ppc64_pic.a libebl_s390_pic.a libebl_tilegx_pic.a \ libebl_m68k_pic.a libebl_bpf_pic.a noinst_LIBRARIES = $(libebl_pic) -noinst_DATA = $(libebl_pic:_pic.a=.so) +libebl_pic_prefixed = $(libebl_pic:lib%=$(LIBPREFIX)%) +noinst_DATA = $(libebl_pic_prefixed:_pic.a=$(LIBEXT)) -libelf = ../libelf/libelf.so -libdw = ../libdw/libdw.so +libelf = ../libelf/$(libelf_BARE) +libdw = ../libdw/$(libdw_BARE) if USE_GNULIB libgnu = ../libgnu/libgnu.a else @@ -134,32 +135,32 @@ libebl_bpf_pic_a_SOURCES = $(bpf_SRCS) am_libebl_bpf_pic_a_OBJECTS = $(bpf_SRCS:.c=.os) -libebl_%.so libebl_%.map: libebl_%_pic.a $(libelf) $(libdw) $(libgnu) - @rm -f $(@:.so=.map) +$(LIBPREFIX)ebl_%$(LIBEXT) $(LIBPREFIX)ebl_%.map: libebl_%_pic.a $(libelf) $(libdw) $(libgnu) + @rm -f $(@:$(LIBEXT)=.map) $(AM_V_at)echo 'ELFUTILS_$(PACKAGE_VERSION) { global: $*_init; local: *; };' \ - > $(@:.so=.map) - $(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $(@:.map=.so) \ + > $(@:$(LIBEXT)=.map) + $(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $(@:.map=$(LIBEXT)) \ -Wl,--whole-archive $< $(cpu_$*) -Wl,--no-whole-archive \ - -Wl,--version-script,$(@:.so=.map) \ + -Wl,--version-script,$(@:$(LIBEXT)=.map) \ -Wl,--as-needed $(libelf) $(libdw) $(libgnu) $(intl_LDADD) @$(textrel_check) -libebl_i386.so: $(cpu_i386) -libebl_x86_64.so: $(cpu_x86_64) -libebl_bpf.so: $(cpu_bpf) +$(LIBPREFIX)ebl_i386$(LIBEXT): $(cpu_i386) +$(LIBPREFIX)ebl_x86_64$(LIBEXT): $(cpu_x86_64) +$(LIBPREFIX)ebl_bpf$(LIBEXT): $(cpu_bpf) install: install-am install-ebl-modules install-ebl-modules: $(mkinstalldirs) $(DESTDIR)$(libdir)/$(LIBEBL_SUBDIR) for m in $(modules); do \ - $(INSTALL_PROGRAM) libebl_$${m}.so $(DESTDIR)$(libdir)/$(LIBEBL_SUBDIR)/libebl_$${m}-$(PACKAGE_VERSION).so; \ - ln -fs libebl_$${m}-$(PACKAGE_VERSION).so $(DESTDIR)$(libdir)/$(LIBEBL_SUBDIR)/libebl_$${m}.so; \ + $(INSTALL_PROGRAM) $(LIBPREFIX)ebl_$${m}$(LIBEXT) $(DESTDIR)$(libdir)/$(LIBEBL_SUBDIR)/$(LIBPREFIX)ebl_$${m}-$(PACKAGE_VERSION)$(LIBEXT); \ + ln -fs $(LIBPREFIX)ebl_$${m}-$(PACKAGE_VERSION)$(LIBEXT) $(DESTDIR)$(libdir)/$(LIBEBL_SUBDIR)/$(LIBPREFIX)ebl_$${m}$(LIBEXT); \ done uninstall: uninstall-am for m in $(modules); do \ - rm -f $(DESTDIR)$(libdir)/$(LIBEBL_SUBDIR)/libebl_$${m}-$(PACKAGE_VERSION).so; \ - rm -f $(DESTDIR)$(libdir)/$(LIBEBL_SUBDIR)/libebl_$${m}.so; \ + rm -f $(DESTDIR)$(libdir)/$(LIBEBL_SUBDIR)/$(LIBPREFIX)ebl_$${m}-$(PACKAGE_VERSION)$(LIBEXT); \ + rm -f $(DESTDIR)$(libdi
[PATCH] Check native binary format
If our native binary format is not ELF, there is no point in doing the textrel check and we have to exclude some tests that compile source code with the native compiler and then check something on the resulting binary with elfutils. Signed-off-by: Ulf Hermann --- ChangeLog | 4 config/ChangeLog | 4 config/eu.am | 4 configure.ac | 3 +++ tests/ChangeLog| 16 tests/run-disasm-x86-64.sh | 5 + tests/run-disasm-x86.sh| 5 + tests/run-dwfllines.sh | 5 + tests/run-elf_cntl_gelf_getshdr.sh | 5 + tests/run-elflint-self.sh | 5 + tests/run-low_high_pc.sh | 6 ++ tests/run-native-test.sh | 5 + tests/run-nm-self.sh | 5 + tests/run-readelf-self.sh | 5 + tests/run-strip-reloc.sh | 5 + tests/run-strip-strmerge.sh| 5 + tests/test-nlist.c | 6 +- 17 files changed, 92 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3613beb..d43eeb6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2017-04-28 Ulf Hermann + * configure.ac: Determine the binary format we're building natively. + +2017-04-28 Ulf Hermann + * configure.ac: Determine library naming conventions and define LIBPREFIX, LIBEXT and common names for elf, dw, asm accordingly. diff --git a/config/ChangeLog b/config/ChangeLog index 59569e3..0f240ea 100644 --- a/config/ChangeLog +++ b/config/ChangeLog @@ -1,3 +1,7 @@ +2017-04-28 Ulf Hermann + + * eu.am: Disable textrel_check if we're not building ELF files. + 2017-04-27 Ulf Hermann * eu.am: Use fpic_CFLAGS. diff --git a/config/eu.am b/config/eu.am index bc8c767..e692341 100644 --- a/config/eu.am +++ b/config/eu.am @@ -107,7 +107,11 @@ textrel_found = $(textrel_msg); exit 1 else textrel_found = $(textrel_msg) endif +if NATIVE_ELF textrel_check = if $(READELF) -d $@ | fgrep -q TEXTREL; then $(textrel_found); fi +else +textrel_check = +endif print-%: @echo $*=$($*) diff --git a/configure.ac b/configure.ac index b2e03bb..18ef6d6 100644 --- a/configure.ac +++ b/configure.ac @@ -88,6 +88,9 @@ AC_SUBST([LIBPREFIX]) AC_DEFINE_UNQUOTED(LIBPREFIX, "$LIBPREFIX") AH_TEMPLATE([LIBPREFIX], [Host system file name prefix for dynamic libraries.]) AM_CONDITIONAL(POSTFIX_LIB_VERSION, test "$eu_postfix_lib_version" = "yes") +AM_CONDITIONAL(NATIVE_ELF, test "$LIBEXT" = ".so") +AM_CONDITIONAL(NATIVE_PE, test "$LIBEXT" = ".dll") +AM_CONDITIONAL(NATIVE_MACHO, test "$LIBEXT" = ".dylib") eu_LIBNAME(elf,1) eu_LIBNAME(dw,1) diff --git a/tests/ChangeLog b/tests/ChangeLog index d5bda6d..a9bc6fa 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,5 +1,21 @@ 2017-04-28 Ulf Hermann + * run-disasm-x86-64.sh: Disable if the native binary format is not + ELF. + * run-disasm-x86.sh: Likewise. + * run-dwfllines.sh: Likewise. + * run-elf_cntl_gelf_getshdr.sh: Likewise. + * run-elflint-self.sh: Likewise. + * run-low_high_pc.sh: Likewise. + * run-native-test.sh: Likewise. + * run-nm-self.sh: Likewise. + * run-readelf-self.sh: Likewise. + * run-strip-reloc.sh: Likewise. + * run-strip-strmerge.sh: Likewise. + * test-nlist.c: Likewise. + +2017-04-28 Ulf Hermann + * Makefile.am: Use the predefined names for libelf, libdw, libasm, rather than hardcoding to the elf conventions and add the right extension to deleted-lib.. diff --git a/tests/run-disasm-x86-64.sh b/tests/run-disasm-x86-64.sh index a6be62b..c5256b7 100755 --- a/tests/run-disasm-x86-64.sh +++ b/tests/run-disasm-x86-64.sh @@ -17,6 +17,11 @@ . $srcdir/test-subr.sh +if ! grep -q -F '#define LIBEXT ".so"' ${abs_top_builddir}/config.h; then + echo "only works with native ELF binaries." + exit 77 +fi + # Run x86-64 test. case "`uname -m`" in x86_64) diff --git a/tests/run-disasm-x86.sh b/tests/run-disasm-x86.sh index 28a3df7..e0b6ee3 100755 --- a/tests/run-disasm-x86.sh +++ b/tests/run-disasm-x86.sh @@ -17,6 +17,11 @@ . $srcdir/test-subr.sh +if ! grep -q -F '#define LIBEXT ".so"' ${abs_top_builddir}/config.h; then + echo "only works with native ELF binaries." + exit 77 +fi + # Run x86 test. case "`uname -m`" in x86_64 | i?86 ) diff --git a/tests/run-dwfllines.sh b/tests/run-dwfllines.sh index b384de0..c228d7d 100755 --- a/tests/run-dwfllines.sh +++ b/tests/run-dwfllines.sh @@ -83,6 +83,11 @@ mod: CU: [9e4] m.c time: 0, len: 0, idx: 0, b: 1, e: 1, pe: 0, eb: 0, block: 0, isa: 0, disc: 0 EOF +if ! grep -q -F '#define LIBEXT ".so"
Re: [PATCH] Don't look for kernel version if not running on linux
You can get uname() on Windows through gnulib, but at the cost at linking to additional windows DLLs. It calls gethostname and for that we need to link against ws2_32.dll. That's an unreasonable dependency for getting something we cannot use anyway. I suggest we just set errno to ENOTSUP then. I should clarify this a bit. We only use uname() to obtain the kernel version and we only use the kernel version to search for directories containing kernel modules. The only operating system where this makes sense is linux as we cannot handle anything but linux kernel modules there. Therefore there is no point in retrieving the kernel version on any other OS. We might still be able to load linux kernel modules from some directory on a different OS, but the automatic detection of that directory can be skipped. Ulf
Re: [PATCH] Avoid double-including config.h
Maybe we can cleanup that last one once we integrate gnulib (which I believe has a good/64-off_t fts.h already). gnulib is among the bad ones. Or, at least we detect it as bad. Ulf
Re: [PATCH] Make elf section sorting more deterministic
[...] How about the attached? Looks good to me. Ulf
[PATCH] Generate .lib files on PE platforms
MSVC needs them to link against .dll files. gcc can do without, so we only need to do this when actually installing the files. There is a way to generate .lib files with dlltool, but most of the time MSVC won't cleanly link against the result, so we rather use lib.exe here. Signed-off-by: Ulf Hermann --- config/ChangeLog | 5 + config/eu.am | 12 libasm/ChangeLog | 5 + libasm/Makefile.am | 28 +--- libdw/ChangeLog| 5 + libdw/Makefile.am | 28 +--- libelf/ChangeLog | 5 + libelf/Makefile.am | 27 --- 8 files changed, 106 insertions(+), 9 deletions(-) diff --git a/config/ChangeLog b/config/ChangeLog index 0f240ea..34414a3 100644 --- a/config/ChangeLog +++ b/config/ChangeLog @@ -1,3 +1,8 @@ +2017-05-03 Ulf Hermann + + * eu.am: If we're building PE binaries add a rule to build the + frontend .lib files using Microsofts lib.exe. + 2017-04-28 Ulf Hermann * eu.am: Disable textrel_check if we're not building ELF files. diff --git a/config/eu.am b/config/eu.am index e692341..9603668 100644 --- a/config/eu.am +++ b/config/eu.am @@ -113,5 +113,17 @@ else textrel_check = endif +if NATIVE_PE +%.lib: %.def + case '$(host_cpu)' in \ + i?86) \ + lib /machine:x86 /def:$< ;;\ + x86_64) \ + lib /machine:x64 /def:$< ;;\ + arm) \ + lib /machine:arm /def:$< ;;\ + esac; +endif + print-%: @echo $*=$($*) diff --git a/libasm/ChangeLog b/libasm/ChangeLog index 3483e4c..0155d48 100644 --- a/libasm/ChangeLog +++ b/libasm/ChangeLog @@ -1,3 +1,8 @@ +2017-05-03 Ulf Hermann + + * Makefile.am: Output asm.def when linking asm.dll and create asm.lib + when installing. + 2017-04-27 Ulf Hermann * asm_end.c (binary_end): Fix nesting of braces. diff --git a/libasm/Makefile.am b/libasm/Makefile.am index c6038aa..d486db9 100644 --- a/libasm/Makefile.am +++ b/libasm/Makefile.am @@ -61,23 +61,45 @@ endif if USE_GNULIB libasm_so_LDLIBS += ../libgnu/libgnu.a endif +if NATIVE_PE +GEN_DEF = -Wl,--output-def=$(libasm_BARE:.dll=.def) +CLEANFILES += $(libasm_BARE:.dll=.def) +else +GEN_DEF = +endif $(libasm_BARE): libasm_pic.a libasm.map $(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ -Wl,--whole-archive,$<,--no-whole-archive \ -Wl,--version-script,$(srcdir)/libasm.map,--no-undefined \ - -Wl,--soname,$(libasm_SONAME) \ + -Wl,--soname,$(libasm_SONAME) $(GEN_DEF) \ ../libebl/libebl.a ../libelf/$(libelf_BARE) ../libdw/$(libdw_BARE) \ $(libasm_so_LDLIBS) @$(textrel_check) $(AM_V_at)ln -fs $@ $(libasm_SONAME) -install: install-am $(libasm_BARE) +if NATIVE_PE +install-lib: $(libasm_BARE:.dll=.lib) + $(mkinstalldirs) $(DESTDIR)$(libdir) + $(INSTALL_PROGRAM) $< $(DESTDIR)$(libdir)/$(libasm_VERSIONED:.dll=.lib) + ln -fs $(libasm_VERSIONED:.dll=.lib) $(DESTDIR)$(libdir)/$(libasm_SONAME:.dll=.lib) + ln -fs $(libasm_SONAME:.dll=.lib) $(DESTDIR)$(libdir)/$(libasm_BARE:.dll=.lib) +uninstall-lib: + rm -f $(DESTDIR)$(libdir)/$(libasm_VERSIONED:.dll=.lib) + rm -f $(DESTDIR)$(libdir)/$(libasm_SONAME:.dll=.lib) + rm -f $(DESTDIR)$(libdir)/$(libasm_BARE:.dll=.lib) +CLEANFILES += $(libasm_BARE:.dll=.lib) $(libasm_BARE:.dll=.exp) +else +install-lib: +uninstall-lib: +endif + +install: install-am install-lib $(libasm_BARE) $(mkinstalldirs) $(DESTDIR)$(libdir) $(INSTALL_PROGRAM) $(libasm_BARE) $(DESTDIR)$(libdir)/$(libasm_VERSIONED) ln -fs $(libasm_VERSIONED) $(DESTDIR)$(libdir)/$(libasm_SONAME) ln -fs $(libasm_SONAME) $(DESTDIR)$(libdir)/$(libasm_BARE) -uninstall: uninstall-am +uninstall: uninstall-am uninstall-lib rm -f $(DESTDIR)$(libdir)/$(libasm_VERSIONED) rm -f $(DESTDIR)$(libdir)/$(libasm_SONAME) rm -f $(DESTDIR)$(libdir)/$(libasm_BARE) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 615647b..0d94ad5 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,8 @@ +2017-05-03 Ulf Hermann + + * Makefile.am: Output dw.def when linking dw.dll and create dw.lib + when installing. + 2017-02-28 Ulf Hermann * Makefile.am: Use the predefined common library names rather than diff --git a/libdw/Makefile.am b/libdw/Makefile.am index aeb84dc..c6d37e9 100644 --- a/libdw/Makefile.am +++ b/libdw/Makefile.am @@ -103,6 +103,12 @@ PKG_RPATH = -Wl,--enable-new-dtags,-rpath,$(pkglibdir) else PKG_RPATH = endif +if NATIVE_PE +GEN_DEF = -Wl,--output-def=$(libdw_BARE:.dll=.def) +CLEANFILES += $(libdw_BARE:.dll=.def) +else +GEN_DEF = +endif libdw_pic_a_SOURCES = am_libdw_pic_a_OBJECTS = $(libdw_a_SOURCES:.c=.os) @@ -119,19 +125,35 @@ $(libdw_BARE): $(srcdir)/libdw.map libdw_pic.a ../libdwelf/libdwelf_pic.a \ # The rpath is necessary for libebl because its
[PATCH] Check if gcc supports -rdynamic and don't use it if not
On some platforms the symbols are automatically exported and -rdynamic will produce a warning. Signed-off-by: Ulf Hermann --- ChangeLog | 4 configure.ac | 11 +++ tests/ChangeLog | 5 + tests/Makefile.am | 2 +- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d43eeb6..eaea959 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-05-03 Ulf Hermann + + * configure.ac: Add check for -rdynamic. + 2017-04-28 Ulf Hermann * configure.ac: Determine the binary format we're building natively. diff --git a/configure.ac b/configure.ac index 18ef6d6..e45584e 100644 --- a/configure.ac +++ b/configure.ac @@ -237,6 +237,17 @@ fi AC_SUBST([dso_LDFLAGS]) +rdynamic_LDFLAGS="-rdynamic" +AC_CACHE_CHECK([whether gcc supports $rdynamic_LDFLAGS], ac_cv_rdynamic, [dnl +save_LDFLAGS="$LDFLAGS" +LDFLAGS="$rdynamic_LDFLAGS $save_LDFLAGS" +AC_LINK_IFELSE([AC_LANG_PROGRAM()], ac_cv_rdynamic=yes, ac_cv_rdynamic=no) +LDFLAGS="$save_LDFLAGS" +]) +if test "$ac_cv_rdynamic" = "no"; then + rdynamic_LDFLAGS="" +fi + AC_CACHE_CHECK([for rpath support], ac_cv_rpath, [dnl save_LDFLAGS="$LDFLAGS" LDFLAGS="$save_LDFLAGS -Wl,--enable-new-dtags,-rpath,/foo/bar" diff --git a/tests/ChangeLog b/tests/ChangeLog index ab1a3788..b00c848 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,8 @@ +2017-05-03 Ulf Hermann + + * Makefile.am: Skip -rdynamic when compiling deleted-lib.so with a + compiler that doesn't support it. + 2017-04-28 Ulf Hermann * run-disasm-x86-64.sh: Disable if the native binary format is not diff --git a/tests/Makefile.am b/tests/Makefile.am index 943c694..114ab7a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -520,7 +520,7 @@ endif system_elf_libelf_test_LDADD = $(libelf) $(libgnu) deleted-lib$(LIBEXT): deleted-lib.c $(libgnu) - $(AM_V_CCLD)$(COMPILE) $(fpic_CFLAGS) -fasynchronous-unwind-tables -shared -rdynamic -o $@ $^ + $(AM_V_CCLD)$(COMPILE) $(fpic_CFLAGS) -fasynchronous-unwind-tables -shared $(rdynamic_LDFLAGS) -o $@ $^ if GCOV check: check-am coverage -- 2.1.4
Re: pending patches
> - Check for -z,defs, -z,relro, -fPIC, -fPIE before using them > There are actually two versions, I haven't looked yet how they differ. > - Check if gcc complains about __attribute__ (visibility(..)) > - Disable symbol versioning if .symver doesn't work > - Check if rpath is supported before setting it > > In all of the above cases checking for support is a good thing. > But I am a little hesitant about automatically disabling support. > For example our binary compatibility depends on having symbol versioning > support. It seems bad to "silently" break that. And without rpath > support backends aren't found and stuff will mysteriously break. So I > think I prefer configure to error out and have an explicit override > option someone would have to use indicating they are building a broken > elfutils. That can be done. I will post new versions of the patches to add a configure switch. My problem right now is that I have about 50 more patches pending locally and I will be gone from May 12th to sometime in August. So, I probably won't manage to post and fix all of them here before autumn. Yet, I still need them for the Qt Creator (and perfparser) 4.4 release, for which the feature freeze will happen when I'm gone. To deal with this, right now I have a fork of elfutils at http://code.qt.io/cgit/qt-creator/elfutils.git/ which receives the patches before they get here. This is not great and I want to merge it eventually, but I can't clone myself. > - Check if we need -lintl for linking gettext > This looks OK, but I don't know much about gettext support. It's just that mingw doesn't really have a libc and msvcrt.dll doesn't have gettext. So we need to link libintl.a or libintl.dll (as provided by mingw) separately. > - Generalize library names > This looks like a nice cleanup, but I don't know anything about how > non-gnu/linux systems do library sonames (I also use a local hack > sometimes to explicitly set a different version that I should upstream > myself). Well, not at all. It's called dll hell :(. The patch provides binaries with the version encoded into the file name, which can make things somewhat better. However, as dw.dll (and dw1.dll and dw-0.168.dll) link against plain elf.dll, extra hackery is required if you want to use the files with versions encoded. Also you cannot do "-lelf" then, but rather "-lelf1". Ulf
[PATCH] Make sure packed structs follow the gcc memory layout
On windows gcc by default generates code that follows the MSVC layout. We don't want that as it adds extra padding. Signed-off-by: Ulf Hermann --- ChangeLog | 5 + backends/ChangeLog | 4 backends/linux-core-note.c | 2 +- configure.ac | 13 + lib/ChangeLog | 5 + lib/eu-config.h| 8 libcpu/ChangeLog | 4 libcpu/memory-access.h | 2 +- libdw/ChangeLog| 4 libdw/memory-access.h | 2 +- libelf/ChangeLog | 4 libelf/gelf_xlate.c| 2 +- 12 files changed, 51 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index eaea959..392efaa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2017-05-03 Ulf Hermann + * configure.ac: Check if the compiler supports + __attribute__((gcc_struct)). + +2017-05-03 Ulf Hermann + * configure.ac: Add check for -rdynamic. 2017-04-28 Ulf Hermann diff --git a/backends/ChangeLog b/backends/ChangeLog index 8985f7c..caefcf4 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,7 @@ +2017-05-03 Ulf Hermann + + * linux-core-note.c: Use attribute_packed. + 2017-04-06 Mark Wielaard * i386_unwind.c: New file. diff --git a/backends/linux-core-note.c b/backends/linux-core-note.c index 67638d7..08282ba 100644 --- a/backends/linux-core-note.c +++ b/backends/linux-core-note.c @@ -111,7 +111,7 @@ struct EBLHOOK(prstatus) FIELD (INT, pr_fpvalid); } #ifdef ALIGN_PRSTATUS - __attribute__ ((packed, aligned (ALIGN_PRSTATUS))) + attribute_packed __attribute__ ((aligned (ALIGN_PRSTATUS))) #endif ; diff --git a/configure.ac b/configure.ac index e45584e..e4b2946 100644 --- a/configure.ac +++ b/configure.ac @@ -185,6 +185,19 @@ if test "$ac_cv_visibility" = "yes"; then [Defined if __attribute__((visibility())) is supported]) fi +AC_CACHE_CHECK([whether gcc supports __attribute__((gcc_struct))], + ac_cv_gcc_struct, [dnl +save_CFLAGS="$CFLAGS" +CFLAGS="$save_CFLAGS -Werror" +AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl +struct test { int x; } __attribute__((gcc_struct)); +])], ac_cv_gcc_struct=yes, ac_cv_gcc_struct=no) +CFLAGS="$save_CFLAGS"]) +if test "$ac_cv_gcc_struct" = "yes"; then + AC_DEFINE([HAVE_GCC_STRUCT], [1], + [Defined if __attribute__((gcc_struct)) is supported]) +fi + AC_CACHE_CHECK([whether gcc supports -fPIC], ac_cv_fpic, [dnl save_CFLAGS="$CFLAGS" CFLAGS="$save_CFLAGS -fPIC -Werror" diff --git a/lib/ChangeLog b/lib/ChangeLog index ecc6179..6c0ac6d 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,8 @@ +2017-05-03 Ulf Hermann + + * eu-config.h: Define attribute_packed to be either only + __attribute__((packed)) or to include gcc_struct if available. + 2017-04-27 Ulf Hermann * eu-config.h: Define attribute_hidden to be empty if the compiler diff --git a/lib/eu-config.h b/lib/eu-config.h index 0709828..135803e 100644 --- a/lib/eu-config.h +++ b/lib/eu-config.h @@ -75,6 +75,14 @@ #define attribute_hidden /* empty */ #endif +#ifdef HAVE_GCC_STRUCT +#define attribute_packed \ + __attribute__ ((packed, gcc_struct)) +#else +#define attribute_packed \ + __attribute__ ((packed)) +#endif + /* Define ALLOW_UNALIGNED if the architecture allows operations on unaligned memory locations. */ #define SANITIZE_UNDEFINED 1 diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog index ef5da58..a50a87b 100644 --- a/libcpu/ChangeLog +++ b/libcpu/ChangeLog @@ -1,3 +1,7 @@ +2017-05-03 Ulf Hermann + + * memory-access.h: Use attribute_packed. + 2017-02-27 Ulf Hermann * Makefile.am: Use fpic_CFLAGS. diff --git a/libcpu/memory-access.h b/libcpu/memory-access.h index 44210e2..779825f 100644 --- a/libcpu/memory-access.h +++ b/libcpu/memory-access.h @@ -90,7 +90,7 @@ union unaligned int16_t s2; int32_t s4; int64_t s8; - } __attribute__ ((packed)); + } attribute_packed; static inline uint16_t read_2ubyte_unaligned (const void *p) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 0d94ad5..f4b9dfb 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,5 +1,9 @@ 2017-05-03 Ulf Hermann + * memory-access.h: Use attribute_packed. + +2017-05-03 Ulf Hermann + * Makefile.am: Output dw.def when linking dw.dll and create dw.lib when installing. diff --git a/libdw/memory-access.h b/libdw/memory-access.h index a749b5a..afb651f 100644 --- a/libdw/memory-access.h +++ b/libdw/memory-access.h @@ -170,7 +170,7 @@ union unaligned int16_t s2; int32_t s4; int64_t s8; - } __attribute__ ((packed)); + } attribute_packed; # define read_2ubyte_unaligned(Dbg, Addr) \ read_2ubyte_unaligned_1 ((Dbg)->other_byte_order, (Addr)) diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 8dfa2b7..52f
Re: pending patches
> - Check for -z,defs, -z,relro, -fPIC, -fPIE before using them > There are actually two versions, I haven't looked yet how they differ. There was a typo in tests/Makefile.am which I fixed in the second version. This change actually doesn't disable symbol versioning or rpath. It just conditionally disables PIC, PIE, making sections read-only after relocations, and the assertion that all symbols are defined. This is because on some platforms these are implicitly guaranteed or not applicable and gcc will complain about the "redundant" flags. > - Check if gcc complains about __attribute__ (visibility(..)) This also doesn't disable anything critical. It just makes all symbols visible if the check fails. On some platforms the visibility of symbols cannot be handled with attributes. > - Disable symbol versioning if .symver doesn't work Actually there already is a configure switch to disable symbol versioning. We can use that ... cheers, Ulf
[PATCH v2] Detect if symbol versioning is supported (was "Disable symbol versioning if .symver doesn't work")
If not, throw an error unless symbol versioning was explicitly disabled. Signed-off-by: Ulf Hermann --- ChangeLog| 4 configure.ac | 15 +++ 2 files changed, 19 insertions(+) diff --git a/ChangeLog b/ChangeLog index 01f88f3..22c46c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-05-03 Ulf Hermann + + * configure.ac: Test if symbol versioning is supported. + 2017-04-27 Ulf Hermann * configure.ac: Check if the compiler supports diff --git a/configure.ac b/configure.ac index 0266a36..48b06de 100644 --- a/configure.ac +++ b/configure.ac @@ -376,6 +376,21 @@ AS_IF([test "x$enable_textrelcheck" != "xno"], AC_ARG_ENABLE([symbol-versioning], AS_HELP_STRING([--disable-symbol-versioning], [Disable symbol versioning in shared objects])) + +AC_CACHE_CHECK([whether symbol versioning is supported], ac_cv_symbol_versioning, [dnl +AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl +#define NEW_VERSION(name, version) \ + asm (".symver " #name "," #name "@@@" #version); +int foo(int x) { return x + 1; } +NEW_VERSION (foo, ELFUTILS_12.12) +])], ac_cv_symbol_versioning=yes, ac_cv_symbol_versioning=no)]) +if test "$ac_cv_symbol_versioning" = "no"; then +if test "x$enable_symbol_versioning" != "xno"; then +AC_MSG_ERROR([Symbol versioning is not supported. + Use --disable-symbol-versioning to build without.]) +fi +fi + AM_CONDITIONAL(SYMBOL_VERSIONING, [test "x$enable_symbol_versioning" != "xno"]) AS_IF([test "x$enable_symbol_versioning" = "xno"], [AC_MSG_WARN([Disabling symbol versioning breaks ABI compatibility.]) -- 2.1.4
[PATCH v2] Check if rpath is supported before setting it
Some systems don't have rpath. In that case the backends need to be made available by some external mechanism. Provide a configure switch to explicitly turn off the setting of rpaths. Throw an error if that is not set and rpath is not supported. Signed-off-by: Ulf Hermann --- ChangeLog | 5 + configure.ac | 22 ++ libdw/ChangeLog | 4 libdw/Makefile.am | 9 +++-- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 22c46c6..344ae0b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2017-05-03 Ulf Hermann + * configure.ac: Check if the linker supports -rpath and add a switch + to disable setting of rpath. + +2017-05-03 Ulf Hermann + * configure.ac: Test if symbol versioning is supported. 2017-04-27 Ulf Hermann diff --git a/configure.ac b/configure.ac index 48b06de..598b372 100644 --- a/configure.ac +++ b/configure.ac @@ -204,6 +204,28 @@ fi AC_SUBST([dso_LDFLAGS]) +AC_ARG_ENABLE([rpath], +AS_HELP_STRING([--disable-rpath], [Disable setting of rpath])) + +AC_CACHE_CHECK([for rpath support], ac_cv_rpath, [dnl +save_LDFLAGS="$LDFLAGS" +LDFLAGS="$save_LDFLAGS -Wl,--enable-new-dtags,-rpath,/foo/bar" +AC_LINK_IFELSE([AC_LANG_PROGRAM()], ac_cv_rpath=yes, ac_cv_rpath=no) +LDFLAGS="$save_LDFLAGS" +]) +if test "$ac_cv_rpath" = "no"; then +if test "x$enable_rpath" != "xno"; then +AC_MSG_ERROR([rpath is not supported. + Use --disable-rpath to build without.]) +fi +fi + +AM_CONDITIONAL(RPATH, [test "x$enable_rpath" != "xno"]) +AS_IF([test "x$enable_rpath" = "xno"], + [AC_MSG_WARN([Disabling rpath prevents libdw from automatically +finding the ebl backends.]) + enable_rpath=no],[enable_rpath=yes]) + AC_CACHE_CHECK([for __thread support], ac_cv_tls, [dnl # Use the same flags that we use for our DSOs, so the test is representative. # Some old compiler/linker/libc combinations fail some ways and not others. diff --git a/libdw/ChangeLog b/libdw/ChangeLog index af4aa40..d33ffe3 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,7 @@ +2017-02-28 Ulf Hermann + + * Makefile.am: Don't set rpath if it's disabled. + 2017-02-27 Ulf Hermann * libdwP.h: Use attribute_hidden. diff --git a/libdw/Makefile.am b/libdw/Makefile.am index 31f7012..055e3f1 100644 --- a/libdw/Makefile.am +++ b/libdw/Makefile.am @@ -99,6 +99,12 @@ $(srcdir)/known-dwarf.h: $(top_srcdir)/config/known-dwarf.awk $(srcdir)/dwarf.h mv -f $@.new $@ endif +if RPATH +PKG_RPATH = -Wl,--enable-new-dtags,-rpath,$(pkglibdir) +else +PKG_RPATH = +endif + libdw_pic_a_SOURCES = am_libdw_pic_a_OBJECTS = $(libdw_a_SOURCES:.c=.os) @@ -115,8 +121,7 @@ libdw.so$(EXEEXT): $(srcdir)/libdw.map libdw_pic.a ../libdwelf/libdwelf_pic.a \ # The rpath is necessary for libebl because its $ORIGIN use will # not fly in a setuid executable that links in libdw. $(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ -Wl,--soname,$@.$(VERSION) \ - -Wl,--enable-new-dtags,-rpath,$(pkglibdir) \ - -Wl,--version-script,$<,--no-undefined \ + -Wl,--version-script,$<,--no-undefined $(PKG_RPATH) \ -Wl,--whole-archive $(filter-out $<,$^) -Wl,--no-whole-archive\ -ldl -lz $(intl_LDADD) $(zip_LIBS) $(libgnu) @$(textrel_check) -- 2.1.4
[PATCH] Drop __BEGIN_DECLS and __END_DECLS from elf.h
We don't use those anywhere else and they are not guaranteed to be defined. Also, put the 'extern "C"' after the included headers. Signed-off-by: Ulf Hermann --- libelf/ChangeLog | 4 libelf/elf.h | 10 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libelf/ChangeLog b/libelf/ChangeLog index e947e19..40a2876 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,7 @@ +2017-05-03 Ulf Hermann + + * elf.h: Replace __BEGIN_DECLS and __END_DECLS with extern "C". + 2017-02-28 Ulf Hermann * Makefile.am: Use the predefined common library names rather than diff --git a/libelf/elf.h b/libelf/elf.h index b6112d9..ba385d3 100644 --- a/libelf/elf.h +++ b/libelf/elf.h @@ -21,12 +21,14 @@ #include -__BEGIN_DECLS - /* Standard ELF types. */ #include +#ifdef __cplusplus +extern "C" { +#endif + /* Type for a 16-bit quantity. */ typedef uint16_t Elf32_Half; typedef uint16_t Elf64_Half; @@ -3682,6 +3684,8 @@ enum #define R_BPF_NONE 0 /* No reloc */ #define R_BPF_MAP_FD 1 /* Map fd to pointer */ -__END_DECLS +#ifdef __cplusplus +} +#endif #endif /* elf.h */ -- 2.1.4
[PATCH] Add a "selfcontained" mode to provide missing headers on windows
With MSVC there is no features.h, uid_t, gid_t, mode_t, and pid_t are not defined and there is also no elf.h. To make it possible to build other software against libelf and libdw, install our own version of elf.h, and a bare-bones features.h that provides exactly the above declarations. The features.h declarations are provided like mingw defines them. Signed-off-by: Ulf Hermann --- ChangeLog | 4 configure.ac | 6 ++ lib/ChangeLog | 6 ++ lib/Makefile.am| 11 ++- lib/features.h.in | 43 +++ libelf/ChangeLog | 4 libelf/Makefile.am | 9 - tests/ChangeLog| 5 + tests/Makefile.am | 6 ++ 9 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 lib/features.h.in diff --git a/ChangeLog b/ChangeLog index d43eeb6..cf14aec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-05-03 Ulf Hermann + + * configure.ac: Add an --enable-selfcontained switch. + 2017-04-28 Ulf Hermann * configure.ac: Determine the binary format we're building natively. diff --git a/configure.ac b/configure.ac index e4b2946..1e7778d 100644 --- a/configure.ac +++ b/configure.ac @@ -124,6 +124,12 @@ AS_HELP_STRING([--enable-gnulib], use_gnulib=$enableval, use_gnulib=no) AM_CONDITIONAL(USE_GNULIB, test "$use_gnulib" = yes) +AC_ARG_ENABLE([selfcontained], +AS_HELP_STRING([--enable-selfcontained], + [install extra headers to enable including and linking the libraries on non-GNU systems]), + selfcontained=$enableval, selfcontained=no) +AM_CONDITIONAL(SELFCONTAINED, test "$selfcontained" = yes) + AC_PROG_CC gl_EARLY diff --git a/lib/ChangeLog b/lib/ChangeLog index ecc6179..2da6235 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,9 @@ +2017-05-03 Ulf Hermann + + * features.h.in: New file. + * Makefile.am: In selfcontained mode, install features.h.in as + features.h. + 2017-04-27 Ulf Hermann * eu-config.h: Define attribute_hidden to be empty if the compiler diff --git a/lib/Makefile.am b/lib/Makefile.am index 17d16d0..87a922a 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -39,8 +39,17 @@ libeu_a_SOURCES = xstrdup.c xstrndup.c xmalloc.c next_prime.c \ noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \ md5.h sha1.h eu-config.h color.h printversion.h -EXTRA_DIST = dynamicsizehash.c +EXTRA_DIST = dynamicsizehash.c features.h.in if !GPROF xmalloc_CFLAGS = -ffunction-sections endif + +if SELFCONTAINED +install: install-am features.h.in + $(mkinstalldirs) $(DESTDIR)$(includedir) + $(INSTALL_HEADER) $(top_srcdir)/lib/features.h.in $(DESTDIR)$(includedir)/features.h + +uninstall: uninstall-am + rm -f $(DESTDIR)$(includedir)/features.h +endif diff --git a/lib/features.h.in b/lib/features.h.in new file mode 100644 index 000..6eb3c67 --- /dev/null +++ b/lib/features.h.in @@ -0,0 +1,43 @@ +/* This file defines uid_t, gid_t, mode_t, pid_t + Copyright (C) 2017 The Qt Company Ltd + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + elfutils 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 copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see <http://www.gnu.org/licenses/>. */ + +#ifndef _FEATURES_H +#define _FEATURES_H 1 + +#include + +typedef uint32_t uid_t; +typedef uint32_t gid_t; +typedef uint32_t mode_t; +#ifdef _WIN64 +typedef int64_t pid_t; +#else +typedef int32_t pid_t; +#endif + +#endif /* features.h */ diff --git a/libelf/ChangeLog b/libelf/ChangeLog index e947e19..36da20c 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,7 @@ +2017-05-03 Ulf Hermann + + * Makefile.am: In selfcontained mode, install elf.h. + 2017-02-28 Ulf Hermann * Makefile.am: Use the predefined common library names rather than diff --git a/libelf/Makefile.am b/libelf/Makefile.am index 3286dda..1a2b85a 100644 --- a/libelf/Makefile.am +++ b/libelf/Makefile.am @@ -141,9 +141,16 @@ uninstall: uninstall-am uninstall-lib rm -f $(DESTDIR)$(libdir)/$(libelf_SONAME) rm -f $(DESTDIR)$(libdir)/$(libelf_
[PATCH] If f(un)lockfile is unavailable define it away
Sometimes _POSIX_THREAD_SAFE_FUNCTIONS is still set in this case, which in turn leads to build problems in getopt.c (which would define the functions to nop anyway if it knew they aren't present). Signed-off-by: Ulf Hermann --- lib/ChangeLog | 5 + lib/eu-config.h | 7 +++ 2 files changed, 12 insertions(+) diff --git a/lib/ChangeLog b/lib/ChangeLog index ecc6179..58ee43f 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,8 @@ +2017-05-03 Ulf Hermann + + * eu-config.h: Define flockfile and funlockfile away if gnulib hasn't + detected them. + 2017-04-27 Ulf Hermann * eu-config.h: Define attribute_hidden to be empty if the compiler diff --git a/lib/eu-config.h b/lib/eu-config.h index 135803e..e69b213 100644 --- a/lib/eu-config.h +++ b/lib/eu-config.h @@ -198,5 +198,12 @@ asm (".section predict_data, \"aw\"; .previous\n" # define COMPAT_VERSION(name, version, prefix) error "should use #ifdef SYMBOL_VERSIONING" #endif +#if !HAVE_FLOCKFILE +# define flockfile(fp) /* nop */ +#endif + +#if !HAVE_FUNLOCKFILE +# define funlockfile(fp) /* nop */ +#endif #endif /* eu-config.h */ -- 2.1.4
[PATCH] Add replacement endian.h and byteswap.h to libgnu
Some systems don't provide endian.h and byteswap.h. The required functions are trivial to define using sys/param.h and gcc builtins, though. Also, include endian.h in dwelf_scn_gnu_compressed_size.c as that uses be64toh(). Signed-off-by: Ulf Hermann --- ChangeLog| 4 ++ configure.ac | 6 +++ libdwelf/ChangeLog | 4 ++ libdwelf/dwelf_scn_gnu_compressed_size.c | 1 + libgnu/ChangeLog | 6 +++ libgnu/Makefile.am | 17 +++- libgnu/byteswap.in.h | 38 libgnu/endian.in.h | 75 8 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 libgnu/ChangeLog create mode 100644 libgnu/byteswap.in.h create mode 100644 libgnu/endian.in.h diff --git a/ChangeLog b/ChangeLog index d43eeb6..01f3197 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-05-03 Ulf Hermann + + * configure.ac: Check if endian.h and byteswap.h are available. + 2017-04-28 Ulf Hermann * configure.ac: Determine the binary format we're building natively. diff --git a/configure.ac b/configure.ac index a854013..1e6c844 100644 --- a/configure.ac +++ b/configure.ac @@ -544,6 +544,12 @@ else fi AC_SUBST([intl_LDADD]) +AC_CHECK_DECLS([BYTE_ORDER], [], [], [[#include ]]) +AM_CONDITIONAL(HAVE_ENDIAN_H, [test "x$ac_cv_have_decl_BYTE_ORDER" = "xyes"]) + +AC_CHECK_DECLS([bswap_32], [], [], [[#include ]]) +AM_CONDITIONAL(HAVE_BYTESWAP_H, [test "x$ac_cv_have_decl_bswap_32" = "xyes"]) + dnl Check if we have for EM_BPF disassembly. AC_CHECK_HEADERS(linux/bpf.h) AM_CONDITIONAL(HAVE_LINUX_BPF_H, [test "x$ac_cv_header_linux_bpf_h" = "xyes"]) diff --git a/libdwelf/ChangeLog b/libdwelf/ChangeLog index a332655..29af410 100644 --- a/libdwelf/ChangeLog +++ b/libdwelf/ChangeLog @@ -1,3 +1,7 @@ +2017-05-03 Ulf Hermann + + * dwelf_scn_gnu_compressed_size.c: Include endian.h. + 2015-10-11 Akihiko Odaki * dwelf_strtab.c: Remove sys/param.h include. diff --git a/libdwelf/dwelf_scn_gnu_compressed_size.c b/libdwelf/dwelf_scn_gnu_compressed_size.c index d39b702..6bad8af 100644 --- a/libdwelf/dwelf_scn_gnu_compressed_size.c +++ b/libdwelf/dwelf_scn_gnu_compressed_size.c @@ -30,6 +30,7 @@ # include #endif +#include #include "libdwelfP.h" #include "libelfP.h" diff --git a/libgnu/ChangeLog b/libgnu/ChangeLog new file mode 100644 index 000..ca38be2 --- /dev/null +++ b/libgnu/ChangeLog @@ -0,0 +1,6 @@ +2017-05-03 Ulf Hermann + + * Makefile.am: Make endian.h and byteswap.h available if they don't + exist. + * byteswap.in.h: New file. + * endian.in.h: New file. diff --git a/libgnu/Makefile.am b/libgnu/Makefile.am index 0d31e69..37fdb9c 100644 --- a/libgnu/Makefile.am +++ b/libgnu/Makefile.am @@ -35,7 +35,22 @@ noinst_LIBRARIES = MOSTLYCLEANFILES = MOSTLYCLEANDIRS = BUILT_SOURCES = -EXTRA_DIST = +EXTRA_DIST = endian.in.h byteswap.in.h CLEANFILES = SUFFIXES = + +if !HAVE_ENDIAN_H +endian.h: endian.in.h + $(AM_V_GEN)rm -f $@ && cat $< > $@ +BUILT_SOURCES += endian.h +MOSTLYCLEANFILES += endian.h +endif + +if !HAVE_BYTESWAP_H +byteswap.h: byteswap.in.h + $(AM_V_GEN)rm -f $@ && cat $< > $@ +BUILT_SOURCES += byteswap.h +MOSTLYCLEANFILES += byteswap.h +endif + include gnulib.am diff --git a/libgnu/byteswap.in.h b/libgnu/byteswap.in.h new file mode 100644 index 000..e7b4f29 --- /dev/null +++ b/libgnu/byteswap.in.h @@ -0,0 +1,38 @@ +/* Byteswapping functions for windows + Copyright (C) 2017 The Qt Company Ltd. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + elfutils 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 copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see <http://www.gnu.org/licenses/>. */ + +#ifndef LIB_BYTESWAP_H +#define LIB_BYTESWAP_H 1 + +#include + +#define bswap_16(x) __builtin_bswap16(x) +#define bswap_32(x) __builtin_bswap32(x) +#define bswap_64(x) __builtin_bswap64(x) + +#endif diff --git a/libgnu/
[PATCH] Add mman.h/.c for win32
We cannot get mmap() and friends from gnulib and they don't exist on windows. The functionality we need can be implemnted using native win32 functions, though. Signed-off-by: Ulf Hermann --- configure.ac| 7 +++ libgnu/Makefile.am | 17 +- libgnu/mman_win32.c | 140 libgnu/sys_mman.win32.h | 63 ++ 4 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 libgnu/mman_win32.c create mode 100644 libgnu/sys_mman.win32.h diff --git a/configure.ac b/configure.ac index 1e6c844..6a2f991 100644 --- a/configure.ac +++ b/configure.ac @@ -550,6 +550,13 @@ AM_CONDITIONAL(HAVE_ENDIAN_H, [test "x$ac_cv_have_decl_BYTE_ORDER" = "xyes"]) AC_CHECK_DECLS([bswap_32], [], [], [[#include ]]) AM_CONDITIONAL(HAVE_BYTESWAP_H, [test "x$ac_cv_have_decl_bswap_32" = "xyes"]) +AC_CHECK_HEADERS(sys/mman.h) +AM_CONDITIONAL(HAVE_SYS_MMAN_H, [test "x$ac_cv_header_sys_mman_h" = "xyes"]) +if test "x$ac_cv_header_sys_mman_h" != "xyes"; then + AC_CHECK_DECLS([MapViewOfFile], [], [], [[#include ]]) +fi +AM_CONDITIONAL(USE_WIN32_MMAN, [test "x$ac_cv_have_decl_MapViewOfFile" = "xyes"]) + dnl Check if we have for EM_BPF disassembly. AC_CHECK_HEADERS(linux/bpf.h) AM_CONDITIONAL(HAVE_LINUX_BPF_H, [test "x$ac_cv_header_linux_bpf_h" = "xyes"]) diff --git a/libgnu/Makefile.am b/libgnu/Makefile.am index 37fdb9c..5af121a 100644 --- a/libgnu/Makefile.am +++ b/libgnu/Makefile.am @@ -35,7 +35,7 @@ noinst_LIBRARIES = MOSTLYCLEANFILES = MOSTLYCLEANDIRS = BUILT_SOURCES = -EXTRA_DIST = endian.in.h byteswap.in.h +EXTRA_DIST = endian.in.h byteswap.in.h sys_mman.win32.h mman_win32.c CLEANFILES = SUFFIXES = @@ -53,4 +53,19 @@ BUILT_SOURCES += byteswap.h MOSTLYCLEANFILES += byteswap.h endif +if !HAVE_SYS_MMAN_H +if USE_WIN32_MMAN +sys/mman.h: sys_mman.win32.h + $(AM_V_GEN)rm -f $@ && mkdir -p sys && cat $< > $@ +BUILT_SOURCES += sys/mman.h +MOSTLYCLEANFILES += sys/mman.h +endif +endif + include gnulib.am + +if !HAVE_SYS_MMAN_H +if USE_WIN32_MMAN +libgnu_a_SOURCES += mman_win32.c +endif +endif diff --git a/libgnu/mman_win32.c b/libgnu/mman_win32.c new file mode 100644 index 000..78966c2 --- /dev/null +++ b/libgnu/mman_win32.c @@ -0,0 +1,140 @@ +/* Replacement for mmap(2) and friends on windows + Copyright (C) 2017 The Qt Company Ltd. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + elfutils 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 copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see <http://www.gnu.org/licenses/>. */ + +#include +#include +#include +#include + +void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) +{ +if (fd == -1) { +errno = EBADF; +return MAP_FAILED; +} + +HANDLE file = (HANDLE)_get_osfhandle(fd); +if (file == INVALID_HANDLE_VALUE) { +errno = EBADF; +return MAP_FAILED; +} + +// Apparently there is no writeonly - we might get the write-copy mode to work, though. +DWORD flProtect = PROT_NONE; +if (prot & PROT_READ) { +if (prot & PROT_WRITE) { +if (prot & PROT_EXEC) { +if (flags & MAP_PRIVATE) +flProtect = PAGE_EXECUTE_WRITECOPY; +else +flProtect = PAGE_EXECUTE_READWRITE; +} else { +if (flags & MAP_PRIVATE) +flProtect = PAGE_WRITECOPY; +else +flProtect = PAGE_READWRITE; +} +} else if (prot & PROT_EXEC) { +flProtect = PAGE_EXECUTE_READ; +} +} else if (prot & PROT_EXEC) { +flProtect = PAGE_EXECUTE; +} else { +errno = EPERM; +return MAP_FAILED; +} + +HANDLE fileMapping = CreateFileMapping(file, NULL, flProtect, 0, 0, NULL); +if (fileMapping == NULL) { +errno = EINVAL; // windows docs say this happens on disk full. EINVAL is close enough. +return MAP_FAILED; +} + +//