* [PATCH] readelf: allow build with LLVM/clang @ 2021-07-12 9:59 Tomasz Paweł Gajc 2021-07-14 17:40 ` Mark Wielaard 0 siblings, 1 reply; 4+ messages in thread From: Tomasz Paweł Gajc @ 2021-07-12 9:59 UTC (permalink / raw) To: elfutils-devel convert last nested function to allow build with LLVM/clang. Original patch comes from https://github.com/OpenMandrivaAssociation/elfutils/blob/master/elfutils-0.185-clang.patch Tested with OpenMandriva Lx cooker and LLVM/clang-12.0.1 Signed-off-by: Tomasz Paweł Gajc <tpgxyz@gmail.com> --- configure.ac | 2 +- src/readelf.c | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index b348a717..2b998c9c 100644 --- a/configure.ac +++ b/configure.ac @@ -127,7 +127,7 @@ void baz (int n) ac_cv_c99=yes, ac_cv_c99=no) CFLAGS="$old_CFLAGS"]) AS_IF([test "x$ac_cv_c99" != xyes], - AC_MSG_ERROR([gcc with GNU99 support required])) + AC_MSG_WARN([gcc with GNU99 support required])) AC_CACHE_CHECK([whether gcc supports __attribute__((visibility()))], ac_cv_visibility, [dnl diff --git a/src/readelf.c b/src/readelf.c index 161d7e65..3d6f263e 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -8763,13 +8763,17 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, /* Apply the "operation advance" from a special opcode or DW_LNS_advance_pc (as per DWARF4 6.2.5.1). */ unsigned int op_addr_advance; - inline void advance_pc (unsigned int op_advance) - { - op_addr_advance = minimum_instr_len * ((op_index + op_advance) - / max_ops_per_instr); - address += op_addr_advance; - op_index = (op_index + op_advance) % max_ops_per_instr; - } + bool show_op_index; + #define advance_pc(op_advance_arg) \ + ( { \ + unsigned int op_advance = op_advance_arg; \ + op_addr_advance = minimum_instr_len * ((op_index + (op_advance)) \ + / max_ops_per_instr); \ + address += (op_advance); \ + show_op_index = (op_index > 0 || \ + (op_index + (op_advance)) % max_ops_per_instr > 0); \ + op_index = (op_index + (op_advance)) % max_ops_per_instr; \ + } ) if (max_ops_per_instr == 0) { -- 2.32.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] readelf: allow build with LLVM/clang 2021-07-12 9:59 [PATCH] readelf: allow build with LLVM/clang Tomasz Paweł Gajc @ 2021-07-14 17:40 ` Mark Wielaard 2021-07-15 5:46 ` Timm Baeder 0 siblings, 1 reply; 4+ messages in thread From: Mark Wielaard @ 2021-07-14 17:40 UTC (permalink / raw) To: Tomasz Paweł Gajc; +Cc: elfutils-devel Hi Tomasz, On Mon, Jul 12, 2021 at 11:59:41AM +0200, Tomasz Paweł Gajc via Elfutils-devel wrote: > convert last nested function to allow build with > LLVM/clang. Original patch comes from > https://github.com/OpenMandrivaAssociation/elfutils/blob/master/elfutils-0.185-clang.patch > Tested with OpenMandriva Lx cooker and LLVM/clang-12.0.1 > [...] > --- a/configure.ac > +++ b/configure.ac > @@ -127,7 +127,7 @@ void baz (int n) > ac_cv_c99=yes, ac_cv_c99=no) > CFLAGS="$old_CFLAGS"]) > AS_IF([test "x$ac_cv_c99" != xyes], > - AC_MSG_ERROR([gcc with GNU99 support required])) > + AC_MSG_WARN([gcc with GNU99 support required])) I don't think this is correct. If you believe the testcase is (now) wrong because it tests for an unneeded feature please just adjust the test. > AC_CACHE_CHECK([whether gcc supports __attribute__((visibility()))], > ac_cv_visibility, [dnl > diff --git a/src/readelf.c b/src/readelf.c > index 161d7e65..3d6f263e 100644 > --- a/src/readelf.c > +++ b/src/readelf.c > @@ -8763,13 +8763,17 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, > /* Apply the "operation advance" from a special opcode > or DW_LNS_advance_pc (as per DWARF4 6.2.5.1). */ > unsigned int op_addr_advance; > - inline void advance_pc (unsigned int op_advance) > - { > - op_addr_advance = minimum_instr_len * ((op_index + op_advance) > - / max_ops_per_instr); > - address += op_addr_advance; > - op_index = (op_index + op_advance) % max_ops_per_instr; > - } > + bool show_op_index; > + #define advance_pc(op_advance_arg) \ > + ( { \ > + unsigned int op_advance = op_advance_arg; \ > + op_addr_advance = minimum_instr_len * ((op_index + (op_advance)) \ > + / max_ops_per_instr); \ > + address += (op_advance); \ > + show_op_index = (op_index > 0 || \ > + (op_index + (op_advance)) % max_ops_per_instr > 0); \ > + op_index = (op_index + (op_advance)) % max_ops_per_instr; \ > + } ) This doesn't compile with gcc: readelf.c: In function ‘print_debug_line_section’: readelf.c:8766:12: error: variable ‘show_op_index’ set but not used [-Werror=unused-but-set-variable] 8766 | bool show_op_index; | ^~~~~~~~~~~~~ cc1: all warnings being treated as errors Removing the unused show_op_index makes two testcases fail: FAIL: run-readelf-line.sh ========================= --- readelf.out 2021-07-14 19:37:00.962372827 +0200 +++ - 2021-07-14 19:37:00.971161054 +0200 @@ -42,13 +42,13 @@ [ 36] set prologue end flag [ 37] special opcode 19: address+0 = 0x100005a4 <main>, line+1 = 6 [ 38] set column to 8 - [ 3a] special opcode 47: address+8 = 0x100005a6 <main+0x2>, line+1 = 7 + [ 3a] special opcode 47: address+8 = 0x100005ac <main+0x8>, line+1 = 7 [ 3b] set 'is_stmt' to 0 [ 3c] advance line by constant -7 to 0 - [ 3e] special opcode 32: address+4 = 0x100005a7 <main+0x3>, line+0 = 0 + [ 3e] special opcode 32: address+4 = 0x100005b0 <main+0xc>, line+0 = 0 [ 3f] set column to 3 [ 41] set 'is_stmt' to 1 - [ 42] special opcode 108: address+24 = 0x100005ad <main+0x9>, line+6 = 6 - [ 43] special opcode 76: address+16 = 0x100005b1 <main+0xd>, line+2 = 8 - [ 44] advance address by 32 to 0x100005b9 <main+0x15> + [ 42] special opcode 108: address+24 = 0x100005c8 <main+0x24>, line+6 = 6 + [ 43] special opcode 76: address+16 = 0x100005d8 <main+0x34>, line+2 = 8 + [ 44] advance address by 32 to 0x100005f8 [ 46] extended opcode 1: end of sequence FAIL run-readelf-line.sh (exit status: 1) FAIL: run-readelf-multi-noline.sh ================================= --- readelf.out 2021-07-14 19:37:10.054186557 +0200 +++ - 2021-07-14 19:37:10.062074795 +0200 @@ -112,6 +112,6 @@ [ 6e] extended opcode 2: set address to +0x724 <main> [ 79] copy [ 7a] set column to 15 - [ 7c] special opcode 32: address+4 = +0x725 <main+0x1>, line+0 = 1 - [ 7d] advance address by 4 to +0x726 <main+0x2> + [ 7c] special opcode 32: address+4 = +0x728 <main+0x4>, line+0 = 1 + [ 7d] advance address by 4 to +0x72c [ 7f] extended opcode 1: end of sequence FAIL run-readelf-multi-noline.sh (exit status: 1) Cheers, Mark ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] readelf: allow build with LLVM/clang 2021-07-14 17:40 ` Mark Wielaard @ 2021-07-15 5:46 ` Timm Baeder 2021-07-15 12:10 ` Mark Wielaard 0 siblings, 1 reply; 4+ messages in thread From: Timm Baeder @ 2021-07-15 5:46 UTC (permalink / raw) To: Mark Wielaard, Tomasz Paweł Gajc; +Cc: elfutils-devel On 14/07/2021 19:40, Mark Wielaard wrote: >> AC_CACHE_CHECK([whether gcc supports __attribute__((visibility()))], >> ac_cv_visibility, [dnl >> diff --git a/src/readelf.c b/src/readelf.c >> index 161d7e65..3d6f263e 100644 >> --- a/src/readelf.c >> +++ b/src/readelf.c >> @@ -8763,13 +8763,17 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, >> /* Apply the "operation advance" from a special opcode >> or DW_LNS_advance_pc (as per DWARF4 6.2.5.1). */ >> unsigned int op_addr_advance; >> - inline void advance_pc (unsigned int op_advance) >> - { >> - op_addr_advance = minimum_instr_len * ((op_index + op_advance) >> - / max_ops_per_instr); >> - address += op_addr_advance; >> - op_index = (op_index + op_advance) % max_ops_per_instr; >> - } >> + bool show_op_index; >> + #define advance_pc(op_advance_arg) \ >> + ( { \ >> + unsigned int op_advance = op_advance_arg; \ >> + op_addr_advance = minimum_instr_len * ((op_index + (op_advance)) \ >> + / max_ops_per_instr); \ >> + address += (op_advance); \ >> + show_op_index = (op_index > 0 || \ >> + (op_index + (op_advance)) % max_ops_per_instr > 0); \ >> + op_index = (op_index + (op_advance)) % max_ops_per_instr; \ >> + } ) > > This doesn't compile with gcc: > > readelf.c: In function ‘print_debug_line_section’: > readelf.c:8766:12: error: variable ‘show_op_index’ set but not used [-Werror=unused-but-set-variable] > 8766 | bool show_op_index; > | ^~~~~~~~~~~~~ > cc1: all warnings being treated as errors > > Removing the unused show_op_index makes two testcases fail: > > FAIL: run-readelf-line.sh > ========================= > > --- readelf.out 2021-07-14 19:37:00.962372827 +0200 > +++ - 2021-07-14 19:37:00.971161054 +0200 > @@ -42,13 +42,13 @@ > [ 36] set prologue end flag > [ 37] special opcode 19: address+0 = 0x100005a4 <main>, line+1 = 6 > [ 38] set column to 8 > - [ 3a] special opcode 47: address+8 = 0x100005a6 <main+0x2>, line+1 = 7 > + [ 3a] special opcode 47: address+8 = 0x100005ac <main+0x8>, line+1 = 7 > [ 3b] set 'is_stmt' to 0 > [ 3c] advance line by constant -7 to 0 > - [ 3e] special opcode 32: address+4 = 0x100005a7 <main+0x3>, line+0 = 0 > + [ 3e] special opcode 32: address+4 = 0x100005b0 <main+0xc>, line+0 = 0 > [ 3f] set column to 3 > [ 41] set 'is_stmt' to 1 > - [ 42] special opcode 108: address+24 = 0x100005ad <main+0x9>, line+6 = 6 > - [ 43] special opcode 76: address+16 = 0x100005b1 <main+0xd>, line+2 = 8 > - [ 44] advance address by 32 to 0x100005b9 <main+0x15> > + [ 42] special opcode 108: address+24 = 0x100005c8 <main+0x24>, line+6 = 6 > + [ 43] special opcode 76: address+16 = 0x100005d8 <main+0x34>, line+2 = 8 > + [ 44] advance address by 32 to 0x100005f8 > [ 46] extended opcode 1: end of sequence > FAIL run-readelf-line.sh (exit status: 1) > > FAIL: run-readelf-multi-noline.sh > ================================= > > --- readelf.out 2021-07-14 19:37:10.054186557 +0200 > +++ - 2021-07-14 19:37:10.062074795 +0200 > @@ -112,6 +112,6 @@ > [ 6e] extended opcode 2: set address to +0x724 <main> > [ 79] copy > [ 7a] set column to 15 > - [ 7c] special opcode 32: address+4 = +0x725 <main+0x1>, line+0 = 1 > - [ 7d] advance address by 4 to +0x726 <main+0x2> > + [ 7c] special opcode 32: address+4 = +0x728 <main+0x4>, line+0 = 1 > + [ 7d] advance address by 4 to +0x72c > [ 7f] extended opcode 1: end of sequence > FAIL run-readelf-multi-noline.sh (exit status: 1) FWIW, there is a different version of this patch at https://sourceware.org/pipermail/elfutils-devel/2021q1/003674.html that doesn't have those problems as far as I remember. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] readelf: allow build with LLVM/clang 2021-07-15 5:46 ` Timm Baeder @ 2021-07-15 12:10 ` Mark Wielaard 0 siblings, 0 replies; 4+ messages in thread From: Mark Wielaard @ 2021-07-15 12:10 UTC (permalink / raw) To: Timm Baeder; +Cc: Tomasz Paweł Gajc, elfutils-devel Hi Timm, On Thu, Jul 15, 2021 at 07:46:15AM +0200, Timm Baeder via Elfutils-devel wrote: > FWIW, there is a different version of this patch at > https://sourceware.org/pipermail/elfutils-devel/2021q1/003674.html > that doesn't have those problems as far as I remember. Indeed, that looks more clean. I still like the nested function approach better since it is more concise. But I added a ChangeLog entry and pushed the above as: commit 779c57ea864d104bad88455535df9b26336349fd Author: Timm Bäder <tbaeder@redhat.com> Date: Thu Mar 18 10:25:24 2021 +0100 readelf: Pull advance_pc() in file scope Make advance_pc() a static function so we can get rid of another nested function. Rename it to run_advance_pc() and use a local advance_pc() macro to pass all the local variables. This is similar to what the equivalent code in libdw/dwarf_getsrclines.c is doing. Signed-off-by: Timm Bäder <tbaeder@redhat.com> Sorry I missed this patch earilier. If there are any other pending patches that need review please ping them. Cheers, Mark ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-07-15 12:10 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-07-12 9:59 [PATCH] readelf: allow build with LLVM/clang Tomasz Paweł Gajc 2021-07-14 17:40 ` Mark Wielaard 2021-07-15 5:46 ` Timm Baeder 2021-07-15 12:10 ` Mark Wielaard
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).