We need to append-to rather than set CXXFLAGS, otherwise we loose -O2 & -pipe from our defaults. Currently this results in zeromq being built without optimizations at all (or whatever the compiler would default too, essentially  always -O0).
Bdb is the same, for the CXX portion of its code. C code has been built with -O2. Boost has actually been unaffected because it receives -O3 from it’s own build flags.
Noticed while reworking #22380. For bdb & zeromq, I assume (haven’t checked) this has been the case since #7165.
You can inspect the effcts in bitcoind comparing a function from a unoptimised library, i.e libzmq.
Build bitcoind with zeromq from depends (7be143a960e2bb9ac81144f55c45731c1bb209c5):
0gmake -C depends NO_QT=1 NO_UPNP=1 NO_NATPMP=1 NO_WALLET=1 -j9
1
2./autogen.sh
3CONFIG_SITE=/path/to/share/config.site ./configure
4gmake -C src bitcoind -j9
Find a zeromq function:
0nm -C src/bitcoind | rg zmq
1...
2000000010053a7e0 T _zmq_ctx_new
Disassemble it:
 0lldb src/bitcoind
 1disassemble -a 000000010053a7e0
 2...
 3bitcoind`zmq_ctx_new:
 4bitcoind[0x10053a7e0] <+0>:   pushq  %rbp
 5bitcoind[0x10053a7e1] <+1>:   movq   %rsp, %rbp
 6bitcoind[0x10053a7e4] <+4>:   subq   $0x50, %rsp
 7bitcoind[0x10053a7e8] <+8>:   callq  0x1004b2ee0               ; zmq::initialize_network()
 8bitcoind[0x10053a7ed] <+13>:  testb  $0x1, %al
 9bitcoind[0x10053a7ef] <+15>:  jne    0x10053a802               ; <+34>
10bitcoind[0x10053a7f5] <+21>:  movq   $0x0, -0x8(%rbp)
11bitcoind[0x10053a7fd] <+29>:  jmp    0x10053a8e8               ; <+264>
12bitcoind[0x10053a802] <+34>:  movq   0xadab7(%rip), %rsi       ; (void *)0x0000000000000000
13bitcoind[0x10053a809] <+41>:  movl   $0x2b8, %edi              ; imm = 0x2B8 
14bitcoind[0x10053a80e] <+46>:  callq  0x100556c58               ; symbol stub for: operator new(unsigned long, std::nothrow_t const&)
15bitcoind[0x10053a813] <+51>:  xorl   %ecx, %ecx
16bitcoind[0x10053a815] <+53>:  movl   %ecx, %edx
17bitcoind[0x10053a817] <+55>:  movb   $0x0, -0x19(%rbp)
18bitcoind[0x10053a81b] <+59>:  cmpq   $0x0, %rax
19bitcoind[0x10053a81f] <+63>:  movq   %rax, -0x38(%rbp)
20bitcoind[0x10053a823] <+67>:  movq   %rdx, -0x40(%rbp)
21bitcoind[0x10053a827] <+71>:  je     0x10053a858               ; <+120>
22bitcoind[0x10053a82d] <+77>:  movq   -0x38(%rbp), %rax
23bitcoind[0x10053a831] <+81>:  movq   %rax, -0x18(%rbp)
24bitcoind[0x10053a835] <+85>:  movb   $0x1, -0x19(%rbp)
25bitcoind[0x10053a839] <+89>:  movq   -0x38(%rbp), %rdi
26bitcoind[0x10053a83d] <+93>:  movq   %rax, -0x48(%rbp)
27bitcoind[0x10053a841] <+97>:  callq  0x100497aa0               ; zmq::ctx_t::ctx_t()
28bitcoind[0x10053a846] <+102>: jmp    0x10053a84b               ; <+107>
29bitcoind[0x10053a84b] <+107>: movq   -0x48(%rbp), %rax
30bitcoind[0x10053a84f] <+111>: movq   %rax, -0x40(%rbp)
31bitcoind[0x10053a853] <+115>: jmp    0x10053a858               ; <+120>
32bitcoind[0x10053a858] <+120>: movq   -0x40(%rbp), %rax
33bitcoind[0x10053a85c] <+124>: movq   %rax, -0x10(%rbp)
34bitcoind[0x10053a860] <+128>: cmpq   $0x0, -0x10(%rbp)
35bitcoind[0x10053a865] <+133>: je     0x10053a8e0               ; <+256>
36bitcoind[0x10053a86b] <+139>: movq   -0x10(%rbp), %rdi
37bitcoind[0x10053a86f] <+143>: callq  0x100497ee0               ; zmq::ctx_t::valid() const
38bitcoind[0x10053a874] <+148>: testb  $0x1, %al
39bitcoind[0x10053a876] <+150>: jne    0x10053a8db               ; <+251>
40bitcoind[0x10053a87c] <+156>: movq   -0x10(%rbp), %rax
41bitcoind[0x10053a880] <+160>: cmpq   $0x0, %rax
42bitcoind[0x10053a884] <+164>: movq   %rax, -0x50(%rbp)
43bitcoind[0x10053a888] <+168>: je     0x10053a8a3               ; <+195>
44bitcoind[0x10053a88e] <+174>: movq   -0x50(%rbp), %rdi
45bitcoind[0x10053a892] <+178>: callq  0x100497ec0               ; zmq::ctx_t::~ctx_t()
46bitcoind[0x10053a897] <+183>: movq   -0x50(%rbp), %rax
47bitcoind[0x10053a89b] <+187>: movq   %rax, %rdi
48bitcoind[0x10053a89e] <+190>: callq  0x100556c3a               ; symbol stub for: operator delete(void*)
49bitcoind[0x10053a8a3] <+195>: movq   $0x0, -0x8(%rbp)
50bitcoind[0x10053a8ab] <+203>: jmp    0x10053a8e8               ; <+264>
51bitcoind[0x10053a8b0] <+208>: movq   %rax, -0x28(%rbp)
52bitcoind[0x10053a8b4] <+212>: movl   %edx, -0x2c(%rbp)
53bitcoind[0x10053a8b7] <+215>: testb  $0x1, -0x19(%rbp)
54bitcoind[0x10053a8bb] <+219>: jne    0x10053a8c6               ; <+230>
55bitcoind[0x10053a8c1] <+225>: jmp    0x10053a8d6               ; <+246>
56bitcoind[0x10053a8c6] <+230>: movq   0xad9f3(%rip), %rsi       ; (void *)0x0000000000000000
57bitcoind[0x10053a8cd] <+237>: movq   -0x18(%rbp), %rdi
58bitcoind[0x10053a8d1] <+241>: callq  0x100556c40               ; symbol stub for: operator delete(void*, std::nothrow_t const&)
59bitcoind[0x10053a8d6] <+246>: jmp    0x10053a8f2               ; <+274>
60bitcoind[0x10053a8db] <+251>: jmp    0x10053a8e0               ; <+256>
61bitcoind[0x10053a8e0] <+256>: movq   -0x10(%rbp), %rax
62bitcoind[0x10053a8e4] <+260>: movq   %rax, -0x8(%rbp)
63bitcoind[0x10053a8e8] <+264>: movq   -0x8(%rbp), %rax
64bitcoind[0x10053a8ec] <+268>: addq   $0x50, %rsp
65bitcoind[0x10053a8f0] <+272>: popq   %rbp
66bitcoind[0x10053a8f1] <+273>: retq   
67bitcoind[0x10053a8f2] <+274>: movq   -0x28(%rbp), %rdi
68bitcoind[0x10053a8f6] <+278>: callq  0x100556856               ; symbol stub for: _Unwind_Resume
69bitcoind[0x10053a8fb] <+283>: ud2    
70bitcoind[0x10053a8fd] <+285>: nopl   (%rax)
Cleanup and repeat after changing the zeromq cxxflags to be $(package)_cxxflags+=-std=c++17:
0gmake clean
1gmake -C depends NO_QT=1 NO_UPNP=1 NO_NATPMP=1 NO_WALLET=1 -j9
2gmake -C src bitcoind -j9
3
4nm -C src/bitcoind | rg zmq
5...
600000001004d5170 T _zmq_ctx_new
Disassemble the same function which has now been built with -O2:
 0lldb src/bitcoind
 1disassemble -a 00000001004d5170
 2...
 3bitcoind`zmq_ctx_new:
 4bitcoind[0x1004d5170] <+0>:   pushq  %rbp
 5bitcoind[0x1004d5171] <+1>:   movq   %rsp, %rbp
 6bitcoind[0x1004d5174] <+4>:   pushq  %r14
 7bitcoind[0x1004d5176] <+6>:   pushq  %rbx
 8bitcoind[0x1004d5177] <+7>:   callq  0x10049cbc0               ; zmq::initialize_network()
 9bitcoind[0x1004d517c] <+12>:  testb  %al, %al
10bitcoind[0x1004d517e] <+14>:  je     0x1004d51bd               ; <+77>
11bitcoind[0x1004d5180] <+16>:  movq   0xab139(%rip), %rsi       ; (void *)0x0000000000000000
12bitcoind[0x1004d5187] <+23>:  movl   $0x2b8, %edi              ; imm = 0x2B8 
13bitcoind[0x1004d518c] <+28>:  callq  0x1004f0e5a               ; symbol stub for: operator new(unsigned long, std::nothrow_t const&)
14bitcoind[0x1004d5191] <+33>:  testq  %rax, %rax
15bitcoind[0x1004d5194] <+36>:  je     0x1004d51bd               ; <+77>
16bitcoind[0x1004d5196] <+38>:  movq   %rax, %rbx
17bitcoind[0x1004d5199] <+41>:  movq   %rax, %rdi
18bitcoind[0x1004d519c] <+44>:  callq  0x100493400               ; zmq::ctx_t::ctx_t()
19bitcoind[0x1004d51a1] <+49>:  movq   %rbx, %rdi
20bitcoind[0x1004d51a4] <+52>:  callq  0x1004936e0               ; zmq::ctx_t::valid() const
21bitcoind[0x1004d51a9] <+57>:  testb  %al, %al
22bitcoind[0x1004d51ab] <+59>:  jne    0x1004d51bf               ; <+79>
23bitcoind[0x1004d51ad] <+61>:  movq   %rbx, %rdi
24bitcoind[0x1004d51b0] <+64>:  callq  0x1004936d0               ; zmq::ctx_t::~ctx_t()
25bitcoind[0x1004d51b5] <+69>:  movq   %rbx, %rdi
26bitcoind[0x1004d51b8] <+72>:  callq  0x1004f0e42               ; symbol stub for: operator delete(void*)
27bitcoind[0x1004d51bd] <+77>:  xorl   %ebx, %ebx
28bitcoind[0x1004d51bf] <+79>:  movq   %rbx, %rax
29bitcoind[0x1004d51c2] <+82>:  popq   %rbx
30bitcoind[0x1004d51c3] <+83>:  popq   %r14
31bitcoind[0x1004d51c5] <+85>:  popq   %rbp
32bitcoind[0x1004d51c6] <+86>:  retq   
33bitcoind[0x1004d51c7] <+87>:  movq   %rax, %r14
34bitcoind[0x1004d51ca] <+90>:  movq   0xab0ef(%rip), %rsi       ; (void *)0x0000000000000000
35bitcoind[0x1004d51d1] <+97>:  movq   %rbx, %rdi
36bitcoind[0x1004d51d4] <+100>: callq  0x1004f0e48               ; symbol stub for: operator delete(void*, std::nothrow_t const&)
37bitcoind[0x1004d51d9] <+105>: movq   %r14, %rdi
38bitcoind[0x1004d51dc] <+108>: callq  0x1004f0a6a               ; symbol stub for: _Unwind_Resume
39bitcoind[0x1004d51e1] <+113>: ud2    
40bitcoind[0x1004d51e3] <+115>: nopw   %cs:(%rax,%rax)
41bitcoind[0x1004d51ed] <+125>: nopl   (%rax)