cookies

Thursday 25 May 2023

Building whole Postgres with LLVM

Most posts I could find are about building just the libjit with LLVM/CLANG.

So here's my 5 cents on the subject.

I'll be using [V]irtual[M]achine running Debian [12] Testing, with basic building pakages already installed : 

binutils make gcc-12 libtool libss-dev libreadline-dev libxslt1-dev libxml2-dev libpth-dev zlib1g-dev


My usual configure parameters for GCC :

./configure --prefix=/media/pg --with-pam --with-libxml --with-libxslt --with-openssl --with-pgport=5433 --with-llvm LLVM_CONFIG=llvm-config-15 CLANG=clang-15 CFLAGS="-s -O3 -march=native -mtune=native -fno-plt -flto=4" CXXFLAGS="-s -O3 -march=native -mtune=native -fno-plt -flto=4" LDFLAGS="-Wl,-O3,--as-needed,-flto=4"


Packages to add :

libllvm15 lld-15 llvm-15 llvm-15-dev llvm-15-linker-tools llvm-15-runtime llvm-15-tools

clang-15 libclang-common-15-dev libclang-cpp15 libclang1-15

I won't be using https://libcxx.llvm.org since it's not fully baked yet :

C++11 - Complete
C++14 - Complete
C++17 - In Progress
C++20 - In Progress
C++23 - In Progress
C++2c - In Progress

 

My goal is to check if CLANG can handle Postgres sources ;]


So here's my configure for LLVM :

./configure --prefix=/media/pg13 --with-pam --with-libxml --with-libxslt --with-openssl --with-pgport=5433 --with-llvm LLVM_CONFIG=llvm-config-15 CLANG=clang-15 CC=clang-15 CXX=clang-15 CFLAGS="-fuse-ld=lld-15 -s -O3 -march=native -fno-plt -mtune=native -flto" CXXFLAGS="-fuse-ld=lld-15 -s -O3 -march=native -flto -fno-plt -mtune=native" LD=lld-15 AR=llvm-ar-15 RANLIB=llvm-ranlib-15 STRIP=llvm-strip-15

.. and result

configure: using compiler=Debian clang version 15.0.6
configure: using CFLAGS=-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -Wno-deprecated-non-prototype -fuse-ld=lld -s -O3 -march=native -fno-plt -mtune=native -flto
configure: using CPPFLAGS= -D_GNU_SOURCE -I/usr/include/libxml2
configure: using LDFLAGS= -L/usr/lib/llvm-15/lib  -Wl,--as-needed
configure: using CXX=clang
configure: using CXXFLAGS=-Wall -Wpointer-arith -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fuse-ld=lld -s -O3 -march=native -flto -fno-plt -mtune=native
configure: using CLANG=clang
configure: using BITCODE_CFLAGS= -fno-strict-aliasing -fwrapv -Xclang -no-opaque-pointers -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -Wno-deprecated-non-prototype -O2
configure: using BITCODE_CXXFLAGS= -fno-strict-aliasing -fwrapv -Xclang -no-opaque-pointers -O2

 

Using both "-fuse-ld=lld" and "LD=lld" might be redundant, but without at least one of them - even with setting all the llvm/clang tools - clang will use default linker - ld.

 

Even running 'make -d V=1' you won't see which linker clang calls in the end, bummer.

I had to run 'make V=1 &>../zbuild.log &' in background and watch processes in htop. 

 

Everything build nicely for me, resulting binaries a tad smaller than those build with GCC-12.

Postgres - I've tested sources vesion 13.10 and 13.11, server runs, so far no errors.

Is it faster ? maybe ;]

Friday 17 March 2023

Wildfly 26 - dump http request/reponse with body

I've been messing around with WF26 at work lately.

Sadly good 'ol

  <system-properties>
    <property name="org.apache.cxf.logging.enabled" value="true"/>
    <property name="com.sun.xml.ws.transport.http.HttpAdapter.dump" value="true"/>
  </system-properties>

doesn't work anymore :(

Most i could find is posts about io.undertow.server.handlers.RequestDumpingHandler

Based on https://issues.redhat.com/browse/UNDERTOW-854

I got WF26 to dump Response + body.

In standalone.xml - in  section <subsystem xmlns="urn:jboss:domain:undertow:12.0"

  <server name="default-server">
..
      <host name="default-host" alias="localhost">
          <location name="/" handler="welcome-content"/>
..
          <filter-ref name="request-dumper"/>
          <filter-ref name="store-response"/>
      </host>
  </server>
  <servlet-container name="default">
..
  </handlers>
  <filters>
    <filter name="request-dumper" class-name="io.undertow.server.handlers.RequestDumpingHandler" module="io.undertow.core"/>
    <filter name="store-response" class-name="io.undertow.server.handlers.StoredResponseHandler" module="io.undertow.core"/>
  </filters>


Adding EagerFormParsingHandler gave me errors - so skip that. 

Ta-ducking-da

2023-03-17 09:30:52,700 INFO  [io.undertow.request.dump] (default task-1)
----------------------------REQUEST---------------------------
               URI=/server-example-rest/rest/test/
 characterEncoding=null
     contentLength=70
       contentType=[application/json;charset=UTF-8]
            header=Connection=Keep-Alive
            header=Accept=application/json;charset=UTF-8,application/xml;charset=UTF-8
            header=Authorization=Basic xxxxxxxxxxxx
            header=Content-Type=application/json;charset=UTF-8
            header=Content-Length=70
            header=User-Agent=Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)
            header=Host=10.20.30.40:8443
            locale=[]
            method=POST
          protocol=HTTP/1.1
       queryString=
        remoteAddr=test/10.20.30.41:55061
        remoteHost=test
            scheme=https
              host=10.20.30.40:8443
        serverPort=8443
          isSecure=true
--------------------------RESPONSE--------------------------
     contentLength=54
       contentType=application/json; charset=UTF-8
            header=Expires=0
            header=Connection=keep-alive
            header=Cache-Control=no-cache, no-store, must-revalidate
            header=Pragma=no-cache
            header=Content-Type=application/json; charset=UTF-8
            header=Content-Length=54
            header=Date=Fri, 17 Mar 2023 08:30:52 GMT
            status=200
body=
{"errors":[],"data":[{"something":"Test","example"}]}