How to define and read CLI arguments for an LLVM Pass with the new Pass Manager? - plugins

I'm wondering if there is a way to define, and read the value of, CLI arguments in an LLVM pass plugin? I'm basing my plugin off of banach-space/llvm-tutor, specifically InjectFuncCall. Let's say I want to pass in an argument -func=foo to say only inject into functions called foo. How exactly do I define this command-line argument?
I tried using the CommandLine 2.0 Library. And saw this Answer, but I can't get opt to recognize my argument.

I have found out that you can use the arguments with the new pass manager if you use opt -load yourLib.so.
In this case the command will look like this:
opt -load ./build/libHelloWorld.so -load-pass-plugin=./build/libHelloWorld.so \
-passes="hello-world" -disable-output -lists MYARG1 -lists MYARG2 ./input_for_hello.ll
Below is the full reproducible example.
HelloWorld.cpp:
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Passes/PassPlugin.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/CommandLine.h"
using namespace llvm;
namespace {
// Here we register the pass arguments
cl::list<std::string> Lists("lists", cl::desc("Specify names"), cl::OneOrMore);
// This method implements what the pass does
void visitor(Function &F) {
// using the pass arguments
for(auto arg: Lists) {
errs() << "arg: " << arg << "\n";
}
errs() << "(llvm-tutor) Hello from: "<< F.getName() << "\n";
errs() << "(llvm-tutor) number of arguments: " << F.arg_size() << "\n";
}
// New PM implementation
struct HelloWorld : PassInfoMixin<HelloWorld> {
// Main entry point, takes IR unit to run the pass on (&F) and the
// corresponding pass manager (to be queried if need be)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
visitor(F);
return PreservedAnalyses::all();
}
};
} // namespace
//-----------------------------------------------------------------------------
// New PM Registration
//-----------------------------------------------------------------------------
llvm::PassPluginLibraryInfo getHelloWorldPluginInfo() {
return {LLVM_PLUGIN_API_VERSION, "HelloWorld", LLVM_VERSION_STRING,
[](PassBuilder &PB) {
PB.registerPipelineParsingCallback(
[](StringRef Name, FunctionPassManager &FPM,
ArrayRef<PassBuilder::PipelineElement>) {
if (Name == "hello-world") {
FPM.addPass(HelloWorld());
return true;
}
return false;
});
}};
}
// This is the core interface for pass plugins. It guarantees that 'opt' will
// be able to recognize HelloWorld when added to the pass pipeline on the
// command line, i.e. via '-passes=hello-world'
extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo
llvmGetPassPluginInfo() {
return getHelloWorldPluginInfo();
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.13.4)
project(llvm-tutor-hello-world)
#===============================================================================
# 1. LOAD LLVM CONFIGURATION
#===============================================================================
# Set this to a valid LLVM installation dir
set(LT_LLVM_INSTALL_DIR "" CACHE PATH "LLVM installation directory")
# Add the location of LLVMConfig.cmake to CMake search paths (so that
# find_package can locate it)
list(APPEND CMAKE_PREFIX_PATH "${LT_LLVM_INSTALL_DIR}/lib/cmake/llvm/")
# FIXME: This is a warkaround for #25. Remove once resolved and use
# find_package(LLVM 11.0.0 REQUIRED CONFIG) instead.
find_package(LLVM REQUIRED CONFIG)
# HelloWorld includes headers from LLVM - update the include paths accordingly
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
#===============================================================================
# 2. LLVM-TUTOR BUILD CONFIGURATION
#===============================================================================
# Use the same C++ standard as LLVM does
set(CMAKE_CXX_STANDARD 14 CACHE STRING "")
# LLVM is normally built without RTTI. Be consistent with that.
if(NOT LLVM_ENABLE_RTTI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
endif()
#===============================================================================
# 3. ADD THE TARGET
#===============================================================================
add_library(HelloWorld SHARED HelloWorld.cpp)
# Allow undefined symbols in shared objects on Darwin (this is the default
# behaviour on Linux)
target_link_libraries(HelloWorld
"$<$<PLATFORM_ID:Darwin>:-undefined dynamic_lookup>")
input_for_hello.ll:
; ModuleID = '../inputs/input_for_hello.c'
source_filename = "../inputs/input_for_hello.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
; Function Attrs: mustprogress nofree norecurse nosync nounwind readnone uwtable willreturn
define dso_local i32 #foo(i32 %0) local_unnamed_addr #0 {
%2 = shl nsw i32 %0, 1
ret i32 %2
}
; Function Attrs: mustprogress nofree norecurse nosync nounwind readnone uwtable willreturn
define dso_local i32 #bar(i32 %0, i32 %1) local_unnamed_addr #0 {
%3 = shl i32 %1, 2
%4 = add nsw i32 %3, %0
ret i32 %4
}
; Function Attrs: mustprogress nofree norecurse nosync nounwind readnone uwtable willreturn
define dso_local i32 #fez(i32 %0, i32 %1, i32 %2) local_unnamed_addr #0 {
%4 = shl i32 %1, 2
%5 = add nsw i32 %4, %0
%6 = shl nsw i32 %5, 1
%7 = mul nsw i32 %2, 3
%8 = add i32 %7, %0
%9 = add i32 %8, %6
ret i32 %9
}
; Function Attrs: mustprogress nofree norecurse nosync nounwind readnone uwtable willreturn
define dso_local i32 #main(i32 %0, i8** nocapture readnone %1) local_unnamed_addr #0 {
ret i32 12915
}
attributes #0 = { mustprogress nofree norecurse nosync nounwind readnone uwtable willreturn "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"uwtable", i32 1}
!2 = !{!"Ubuntu clang version 13.0.1-++20220120110924+75e33f71c2da-1~exp1~20220120231001.58"}
Build steps:
rm -rf ./build
mkdir "build"
cd build || exit
cmake ..
cmake --build .
Run the pass:
opt -load ./build/libHelloWorld.so -load-pass-plugin=./build/libHelloWorld.so \
-passes="hello-world" -disable-output -lists MYARG1 -lists MYARG2 ./input_for_hello.ll
Output:
arg: MYARG1
arg: MYARG2
(llvm-tutor) Hello from: foo
(llvm-tutor) number of arguments: 1
arg: MYARG1
arg: MYARG2
(llvm-tutor) Hello from: bar
(llvm-tutor) number of arguments: 2
arg: MYARG1
arg: MYARG2
(llvm-tutor) Hello from: fez
(llvm-tutor) number of arguments: 3
arg: MYARG1
arg: MYARG2
(llvm-tutor) Hello from: main
(llvm-tutor) number of arguments: 2

Related

BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS used to overload multi-type templates : macro with several args as one

With a regular class BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS works :
>> more dummy.cpp
#include <boost/python.hpp>
using namespace boost::python;
class X
{
public:
X() {};
int twice(int x=5, float y=2.) {return (int)(x*y);};
};
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_twice_overloads, X::twice, 0, 2)
BOOST_PYTHON_MODULE(dummy)
{
class_<X>("X").def("twice", &X::twice, X_twice_overloads(args("x", "y")));
}
>> make
g++ -I /usr/include/python2.7 -o dummy.so -fPIC -shared dummy.cpp -lboost_python -lpython2.7
>> python
Python 2.7.17 (default, Oct 19 2019, 23:36:22)
[GCC 9.2.1 20191008] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dummy; dx = dummy.X(); print dx.twice(), dx.twice(2,-1.)
10 -2
OK, that works.
Now I need to "templatize" a class with one (only) type T :
>> more dummyT.cpp
#include <string>
#include <boost/python.hpp>
using namespace boost::python;
template<typename T>
class Y
{
public:
Y() {};
T twice(T x=5, float y=2.) {return (T)(x*y);};
};
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Yint_twice_overloads, Y<int>::twice, 0, 2)
template<typename T, typename O>
void exportY(std::string type)
{
class_<Y<T>>(type.c_str()).def("twice", &Y<T>::twice, O(args("x", "y")));
};
BOOST_PYTHON_MODULE(dummyT)
{
exportY<int, Yint_twice_overloads>("Yint");
}
>> make dummyT
g++ -I /usr/include/python2.7 -o dummyT.so -fPIC -shared dummyT.cpp -lboost_python -lpython2.7
>> python
Python 2.7.17 (default, Oct 19 2019, 23:36:22)
[GCC 9.2.1 20191008] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dummyT; dy = dummyT.Yint(); print dy.twice(), dy.twice(2,-1.)
10 -2
OK: works fine.
But, now I need to "templatize" a class with 2 types T and U:
>> more dummyTU.cpp
#include <string>
#include <boost/python.hpp>
#include <boost/preprocessor.hpp>
using namespace boost::python;
template<typename T, typename U>
class Z
{
public:
Z() {};
T twice(T x=5, U y=2.) {return (T)(x*y);};
};
#define SEVERAL_ARGS_AS_ONE_EXPAND(a,b) Z<a,b>::twice
#define SEVERAL_ARGS_AS_ONE_EXPAND_EXPAND(a,b) SEVERAL_ARGS_AS_ONE_EXPAND(a,b)
#define SEVERAL_ARGS_AS_ONE(a,b) SEVERAL_ARGS_AS_ONE_EXPAND_EXPAND(a,b)
#define ARGS int, float
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Zintfloat_twice_overloads, SEVERAL_ARGS_AS_ONE(ARGS), 0, 2)
template<typename T, typename U, typename O>
void exportZ(std::string type)
{
class_<Z<T,U>>(type.c_str()).def("twice", &Z<T,U>::twice, O(args("x", "y")));
};
BOOST_PYTHON_MODULE(dummyTU)
{
exportZ<int, float, Zintfloat_twice_overloads>("Zintfloat");
}
>> make dummyTU
g++ -I /usr/include/python2.7 -o dummyTU.so -fPIC -shared dummyTU.cpp -lboost_python -lpython2.7
dummyTU.cpp:19:98: error: macro "SEVERAL_ARGS_AS_ONE" requires 2 arguments, but only 1 given
19 | BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Zintfloat_twice_overloads, SEVERAL_ARGS_AS_ONE(ARGS), 0, 2)
This breaks.
As far as I understand the "double macro expand" trick should make "several args as one", but, this seems to fail. Can't get BOOST_PP_XXX to work either. Is there a way to get this to work ?
Solution:
>> more dummyTU.cpp
#include <string>
#include <boost/python.hpp>
using namespace boost::python;
template<typename T, typename U>
class Z
{
public:
Z() {};
T twice(T x=5, U y=2.) {return (T)(x*y);};
};
#define SEVERAL_ARGS_AS_ONE_EXPAND(a,b) Z<a,b>
#define SEVERAL_ARGS_AS_ONE_EXPAND_EXPAND(...) SEVERAL_ARGS_AS_ONE_EXPAND(__VA_ARGS__)
#define SEVERAL_ARGS_AS_ONE(...) SEVERAL_ARGS_AS_ONE_EXPAND_EXPAND(__VA_ARGS__)
#define N_ARGS() int,float
typedef SEVERAL_ARGS_AS_ONE(N_ARGS()) ZintfloatTD;
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Zintfloat_twice_overloads, ZintfloatTD::twice, 0, 2)
template<typename T, typename U, typename O>
void exportZ(std::string type)
{
class_<Z<T,U>>(type.c_str()).def("twice", &Z<T,U>::twice, O(args("x", "y")));
};
BOOST_PYTHON_MODULE(dummyTU)
{
exportZ<int, float, Zintfloat_twice_overloads>("Zintfloat");
}
>> make dummyTU
g++ -I /usr/include/python2.7 -o dummyTU.so -fPIC -shared dummyTU.cpp -lboost_python -lpython2.7
>> python
Python 2.7.17 (default, Oct 19 2019, 23:36:22)
[GCC 9.2.1 20191008] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dummyTU; dz = dummyTU.Zintfloat(); print dz.twice(), dz.twice(2,-1.)
10 -2

How to run dot command with space in shell?

Using jScript to run a command line remotely. The first three commands work fine. It is not until i get to the dot command after I have opened the sqlite3 data base that it just stops executing. When I run .quit I either get
sqlite> .quit
The filename, directory name, or volume label syntax is incorrect.
or ".import" is not recognized as an internal or external command.
try {
// var ret = oShell.Run('cmd.exe cd c:\\sqlite', 1 /* SW_SHOWNORMAL */, true /* bWaitOnReturn */);
var oShell = WScript.CreateObject("WScript.Shell");
// var ret = oShell.Run("cmd.exe /k #echo Hello", 1 /* SW_SHOWNORMAL */, true/* bWaitOnReturn */);
var ret = oShell.Run('cmd.exe /k cd c:\\sqlite && #echo ".import H:\\\\2019\\\\00028-000-19\\\\QPPData\\\\Directory_Proofs\\\\Index_007.txt test" && sqlite3 F:\\qpp.db; && ".import H:\\\\2019\\\\00028-000-19\\\\QPPData\\\\Directory_Proofs\\\\Index_007.txt test"', 1 /* SW_SHOWNORMAL */, true/* bWaitOnReturn */);
WScript.Echo("ret " + ret);
//var ret = oShell.Run('cmd cd', 1 /* SW_SHOWNORMAL */, true /* bWaitOnReturn */);
}
catch (err) {
WScript.Echo(err);
}

Most UEFI protocols are reported as "unsupported"

I'm writing an EFI executable on a SoC device (Up Board) to help us automate BIOS updates and PXE boots for installating our software on numerous devices.
The problem I have is that seemingly most of the protocols in the specification are "unsupported" on this platform, even basic file system tasks. The only one I've successfully used is the LOADED_IMAGE_PROTOCOL. I'm using gnu-efi to compile the code, basing my code to this example https://mjg59.dreamwidth.org/18773.html. Is there something I'm doing wrong, or is this simply the firmware absolutely not implementing any of the protocols?
The American Megatrends utility "AfuEfix64.efi" is capable of retrieving BIOS information, and the SoC BIOS updates are done using an Intel's EFI executable. Both are closed source, unfortunately. My initial idea would have been to write a script that parses the output from these executables, but I don't think the EFI shell has much features for this type of tasks, so I moved on to writing an EFI executable to perform this.
Minimal code showing this:
#include <efi.h>
#include <efilib.h>
#include <x86_64/efibind.h>
// gnu-efi does not currently define firmware management
// https://raw.githubusercontent.com/tianocore/edk2/master/MdePkg/Include/Protocol/FirmwareManagement.h
#include "efifirmware.h"
// gnu-efi does not currently define this
#define EFI_LOAD_FILE2_PROTOCOL_GUID \
{ 0x4006c0c1, 0xfcb3, 0x403e, \
{ 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d }}
typedef EFI_LOAD_FILE_PROTOCOL EFI_LOAD_FILE2_PROTOCOL;
void tryProtocol(EFI_GUID proto_guid, void** out, const CHAR16* name,
EFI_HANDLE imageHandle, EFI_SYSTEM_TABLE* systemTable) {
EFI_STATUS status;
status = uefi_call_wrapper(systemTable->BootServices->HandleProtocol, 3,
imageHandle, &proto_guid, out);
if (EFI_ERROR(status)) {
Print(L"HandleProtocol error for %s: %r\n", name, status);
} else {
Print(L"Protocol %s is supported\n", name);
}
}
void tryProtocols(EFI_HANDLE imgh, EFI_SYSTEM_TABLE* syst) {
EFI_LOADED_IMAGE* loaded_image = NULL;
EFI_GUID guid_imgprot = LOADED_IMAGE_PROTOCOL;
tryProtocol(guid_imgprot, (void**)&loaded_image,
L"LOADED_IMAGE_PROTOCOL", imgh, syst);
Print(L"Image base: %lx\n", loaded_image->ImageBase);
Print(L"Image size: %lx\n", loaded_image->ImageSize);
Print(L"Image file: %s\n", DevicePathToStr(loaded_image->FilePath));
EFI_FIRMWARE_MANAGEMENT_PROTOCOL* fw_manage = NULL;
EFI_GUID guid_fwman_prot = EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID;
tryProtocol(guid_fwman_prot, (void**)&fw_manage,
L"FIRMWARE_MANAGEMENT_PROTOCOL", imgh, syst);
EFI_LOAD_FILE_PROTOCOL* load_file = NULL;
EFI_GUID guid_loadf_prot = EFI_LOAD_FILE_PROTOCOL_GUID;
tryProtocol(guid_loadf_prot, (void**)&load_file,
L"LOAD_FILE_PROTOCOL", imgh, syst);
EFI_LOAD_FILE2_PROTOCOL* load_file2 = NULL;
EFI_GUID guid_loadf2_prot = EFI_LOAD_FILE2_PROTOCOL_GUID;
tryProtocol(guid_loadf2_prot, (void**)&load_file2,
L"LOAD_FILE2_PROTOCOL", imgh, syst);
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* simple_fs = NULL;
EFI_GUID guid_simple_fs_prot = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
tryProtocol(guid_simple_fs_prot, (void**)&simple_fs,
L"SIMPLE_FILE_SYSTEM_PROTOCOL", imgh, syst);
EFI_DISK_IO_PROTOCOL* disk = NULL;
EFI_GUID guid_disk_io_prot = EFI_DISK_IO_PROTOCOL_GUID;
tryProtocol(guid_disk_io_prot, (void**)&disk,
L"DISK_IO_PROTOCOL", imgh, syst);
EFI_BLOCK_IO_PROTOCOL* block = NULL;
EFI_GUID guid_block_io_prot = EFI_BLOCK_IO_PROTOCOL_GUID;
tryProtocol(guid_block_io_prot, (void**)&block,
L"BLOCK_IO_PROTOCOL", imgh, syst);
}
EFI_STATUS
EFIAPI
efi_main (EFI_HANDLE imageHandle, EFI_SYSTEM_TABLE* systemTable) {
InitializeLib(imageHandle, systemTable);
Print(L"Image loaded\n");
tryProtocols(imageHandle, systemTable);
return EFI_SUCCESS;
}
Here's the output for running it:
EFI Shell version 2.40 [5.11]
Current running mode 1.1.2
Device mapping table
fs0 :HardDisk - Alias hd6b blk0
PciRoot(0x0)/Pci(0x10,0x0)/Ctrl(0x0)/HD(1,GPT,2DCDDADD-8F3A-4A77-94A9-010A8C700BB8,0x800,0x100000)
fs1 :Removable HardDisk - Alias hd9g0a0b blk1
PciRoot(0x0)/Pci(0x14,0x0)/USB(0x6,0x0)/USB(0x0,0x0)/HD(1,MBR,0x528E6A1F,0x800,0x1CDE800)
blk0 :HardDisk - Alias hd6b fs0
PciRoot(0x0)/Pci(0x10,0x0)/Ctrl(0x0)/HD(1,GPT,2DCDDADD-8F3A-4A77-94A9-010A8C700BB8,0x800,0x100000)
blk1 :Removable HardDisk - Alias hd9g0a0b fs1
PciRoot(0x0)/Pci(0x14,0x0)/USB(0x6,0x0)/USB(0x0,0x0)/HD(1,MBR,0x528E6A1F,0x800,0x1CDE800)
blk2 :HardDisk - Alias (null)
PciRoot(0x0)/Pci(0x10,0x0)/Ctrl(0x0)/HD(2,GPT,8AC0F94E-3CA2-4C03-BE00-3A69721CC391,0x100800,0x1C1F7DF)
blk3 :BlockDevice - Alias (null)
PciRoot(0x0)/Pci(0x10,0x0)/Ctrl(0x0)
blk4 :BlockDevice - Alias (null)
PciRoot(0x0)/Pci(0x10,0x0)/Ctrl(0x1)
blk5 :BlockDevice - Alias (null)
PciRoot(0x0)/Pci(0x10,0x0)/Ctrl(0x2)
blk6 :Removable BlockDevice - Alias (null)
PciRoot(0x0)/Pci(0x14,0x0)/USB(0x6,0x0)/USB(0x0,0x0)
Press ESC in 4 seconds to skip startup.nsh, any other key to continue.
fs1:\> tryprotocols.efi
Image loaded
Protocol LOADED_IMAGE_PROTOCOL is supported
Image base: 55BA6000
Image size: F000
Image file: \/tryprotocols.efi
HandleProtocol error for FIRMWARE_MANAGEMENT_PROTOCOL: Unsupported
HandleProtocol error for LOAD_FILE_PROTOCOL: Unsupported
HandleProtocol error for LOAD_FILE2_PROTOCOL: Unsupported
HandleProtocol error for SIMPLE_FILE_SYSTEM_PROTOCOL: Unsupported
HandleProtocol error for DISK_IO_PROTOCOL: Unsupported
HandleProtocol error for BLOCK_IO_PROTOCOL: Unsupported
fs1:\>
And here's the Makefile I use to compile it:
ARCH=x86_64
OBJS=tryprotocols.o
TARGET=tryprotocols.efi
TARGET_SO=$(TARGET:.efi=.so)
GNUEFIDIR=/home/gekko/gnu-efi-3.0.8
EFIINC=$(GNUEFIDIR)/inc
EFIINCS=-I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol
LIB=$(GNUEFIDIR)/$(ARCH)/lib
EFILIB=$(GNUEFIDIR)/gnuefi
EFI_CRT_OBJS=$(GNUEFIDIR)/$(ARCH)/gnuefi/crt0-efi-$(ARCH).o
EFI_LDS=$(EFILIB)/elf_$(ARCH)_efi.lds
CFLAGS=$(EFIINCS) -fno-stack-protector -fpic \
-fshort-wchar -mno-red-zone -Wall
ifeq ($(ARCH),x86_64)
CFLAGS += -DEFI_FUNCTION_WRAPPER
endif
LDFLAGS=-nostdlib -znocombreloc -T $(EFI_LDS) -shared \
-Bsymbolic -L $(EFILIB) -L $(LIB) $(EFI_CRT_OBJS)
all: $(TARGET)
$(TARGET_SO): $(OBJS)
ld $(LDFLAGS) $(OBJS) -o $# -lefi -lgnuefi
%.efi: %.so
objcopy -j .text -j .sdata -j .data -j .dynamic \
-j .dynsym -j .rel -j .rela -j .reloc \
--target=efi-app-$(ARCH) $^ $#
clean:
rm -f *.o
rm -f $(TARGET)
rm -f $(TARGET_SO)
EDIT: Modified version that properly uses LocateProtocol() to find the protocols, and uses them to open and close a file.
#include <efi.h>
#include <efilib.h>
#include <x86_64/efibind.h>
BOOLEAN tryProtocol(EFI_GUID proto_guid, void** out, const CHAR16* name,
EFI_HANDLE imageHandle, EFI_SYSTEM_TABLE* systemTable) {
*out = NULL;
EFI_STATUS status;
EFI_HANDLE interface = NULL;
status = uefi_call_wrapper(systemTable->BootServices->LocateProtocol, 3,
&proto_guid, NULL, &interface);
if (EFI_ERROR(status)) {
Print(L"LocateProtocol error for %s: %r\n", name, status);
return FALSE;
}
Print(L"Locate protocol address: %s, %x\n", name, interface);
*out = interface;
return TRUE;
}
EFI_STATUS
EFIAPI
efi_main (EFI_HANDLE imageHandle, EFI_SYSTEM_TABLE* systemTable) {
InitializeLib(imageHandle, systemTable);
Print(L"Image loaded\n");
EFI_LOADED_IMAGE* loaded_image = NULL;
EFI_GUID guid_imgprot = LOADED_IMAGE_PROTOCOL;
if (tryProtocol(guid_imgprot, (void**)&loaded_image,
L"LOADED_IMAGE_PROTOCOL", imageHandle, systemTable) != TRUE) {
Print(L"Missing required protocol. Aborting\n");
return EFI_SUCCESS;
}
Print(L"Image base: %lx\n", loaded_image->ImageBase);
Print(L"Image size: %lx\n", loaded_image->ImageSize);
Print(L"Image file: %s\n", DevicePathToStr(loaded_image->FilePath));
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* simple_fs = NULL;
EFI_GUID guid_simple_fs_prot = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
if (tryProtocol(guid_simple_fs_prot, (void**)&simple_fs,
L"EFI_SIMPLE_FILE_SYSTEM_PROTOCOL", imageHandle, systemTable) != TRUE) {
Print(L"Missing required protocol. Aborting\n");
return EFI_SUCCESS;
}
EFI_FILE_PROTOCOL* vol_proto = NULL;
EFI_STATUS status;
Print(L"dereffing\n");
Print(L"address of OpenVolume: %x\n", simple_fs->OpenVolume);
status = uefi_call_wrapper(simple_fs->OpenVolume, 2, simple_fs, &vol_proto);
if (EFI_ERROR(status)) {
Print(L"Error opening volume: %r\n", status);
return EFI_SUCCESS;
}
Print(L"SIMPLE_FILE_SYSTEM volume opened\n");
EFI_FILE_PROTOCOL* f;
CHAR16 fname[10] = L"foo.txt\0";
UINT64 openmode = EFI_FILE_MODE_READ;
UINT64 attr = 0;
status = uefi_call_wrapper(vol_proto->Open, 5, vol_proto, &f, fname, openmode, attr);
if (EFI_ERROR(status)) {
Print(L"Error opening file: %r\n", status);
return EFI_SUCCESS;
}
Print(L"opened file %s\n", fname);
// Spec says can only return EFI_SUCCESS
status = uefi_call_wrapper(vol_proto->Close, 1, f);
Print(L"Closed file\n");
return EFI_SUCCESS;
}
Where and how to access a specific protocol is not statically defined by the UEFI specification, but something that needs to be discovered at runtime. While a bit arduous, it makes it possible to write applications/drivers portable across vastly different UEFI implementations that all conform to the specification.
So you need to LocateProtocol() on each protocol you are intending to use before you can make use of HandleProtocol().
You get away with LOADED_IMAGE_PROTOCOL because that one is initialized with your ImageHandle referring to the instance of the currently executing image (your program).
This is covered in Matthew's post under the section That covers how to use protocols attached to the image handle. How about protocols that are attached to other handles?.

Adding support for 32-bit Ubuntu to Swift

I'm trying to build Swift from source on a 32-bit Ubuntu virtual machine.
I've done the following modifications, mostly in the build scripts:
(see https://pastebin.com/rmWecTu7)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 112b5d6..16db3ba 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
## -538,12 +538,16 ##
endif()
endif()
+message(STATUS ">>> CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR})
+
# If SWIFT_HOST_VARIANT_ARCH not given, try to detect from the CMAKE_SYSTEM_PROCESSOR.
if(SWIFT_HOST_VARIANT_ARCH)
set(SWIFT_HOST_VARIANT_ARCH_default, "${SWIFT_HOST_VARIANT_ARCH}")
else()
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
set(SWIFT_HOST_VARIANT_ARCH_default "x86_64")
+ elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
+ set(SWIFT_HOST_VARIANT_ARCH_default "i686")
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
set(SWIFT_HOST_VARIANT_ARCH_default "aarch64")
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
## -613,10 +617,14 ##
set(SWIFT_HOST_VARIANT "linux" CACHE STRING
"Deployment OS for Swift host tools (the compiler) [linux].")
+ message(STATUS ">>> SWIFT_HOST_VARIANT_ARCH: " ${SWIFT_HOST_VARIANT_ARCH})
+
# Calculate the host triple
if("${SWIFT_HOST_TRIPLE}" STREQUAL "")
if("${SWIFT_HOST_VARIANT_ARCH}" STREQUAL "x86_64")
set(SWIFT_HOST_TRIPLE "x86_64-unknown-linux-gnu")
+ elseif("${SWIFT_HOST_VARIANT_ARCH}" STREQUAL "i686")
+ set(SWIFT_HOST_TRIPLE "i686-unknown-linux-gnu")
elseif("${SWIFT_HOST_VARIANT_ARCH}" STREQUAL "aarch64")
set(SWIFT_HOST_TRIPLE "aarch64-unknown-linux-gnu")
elseif("${SWIFT_HOST_VARIANT_ARCH}" MATCHES "(powerpc64|powerpc64le)")
diff --git a/stdlib/public/SwiftShims/LibcShims.h b/stdlib/public/SwiftShims/LibcShims.h
index e726a62..5fd7826 100644
--- a/stdlib/public/SwiftShims/LibcShims.h
+++ b/stdlib/public/SwiftShims/LibcShims.h
## -33,7 +33,9 ##
// This declaration is not universally correct. We verify its correctness for
// the current platform in the runtime code.
-#if defined(__linux__) && defined (__arm__)
+#if defined(__linux__) && defined(__arm__)
+typedef int __swift_ssize_t;
+#elif defined(__linux__) && defined(__i386__)
typedef int __swift_ssize_t;
#elif defined(_WIN32)
#if defined(_M_ARM) || defined(_M_IX86)
diff --git a/utils/build-script-impl b/utils/build-script-impl
index 1bfbcc5..b058b22 100755
--- a/utils/build-script-impl
+++ b/utils/build-script-impl
## -449,6 +449,9 ##
--$(tolower "${PLAYGROUNDLOGGER_BUILD_TYPE}")
)
;;
+ linux-i686)
+ SWIFT_HOST_VARIANT_ARCH="i686"
+ ;;
linux-armv6)
SWIFT_HOST_VARIANT_ARCH="armv6"
SWIFT_HOST_TRIPLE="armv6-unknown-linux-gnueabihf"
diff --git a/utils/swift_build_support/swift_build_support/targets.py b/utils/swift_build_support/swift_build_support/targets.py
index f4b5bb0..690a3d3 100644
--- a/utils/swift_build_support/swift_build_support/targets.py
+++ b/utils/swift_build_support/swift_build_support/targets.py
## -112,6 +112,7 ##
is_simulator=True)
Linux = Platform("linux", archs=[
+ "i686",
"x86_64",
"armv6",
"armv7",
## -174,6 +175,8 ##
return StdlibDeploymentTarget.Linux.powerpc64le
elif machine == 's390x':
return StdlibDeploymentTarget.Linux.s390x
+ elif machine == 'i686':
+ return StdlibDeploymentTarget.Linux.i686
elif system == 'Darwin':
if machine == 'x86_64':
Build fails when trying to build stdlib, giving some error related to Float80: (see https://pastebin.com/ue8MRquU)
swift: /home/gigi/local/Source/apple/swift/lib/IRGen/StructLayout.cpp:357: void swift::irgen::StructLayoutBuilder::setAsBodyOfStruct(llvm::StructType *) const: Assertion `(!isFixedLayout() || IGM.DataLayout.getStructLayout(type)->getSizeInBytes() == CurSize.getValue()) && "LLVM size of fixed struct type does not match StructLayout size"' failed.
/home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/swift-linux-i686/bin/swift[0xc335ea0]
Stack dump:
0. Program arguments: /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/swift-linux-i686/bin/swift -frontend -c -filelist /tmp/sources-628097 -disable-objc-attr-requires-foundation-module -target i686-unknown-linux-gnu -disable-objc-interop -sdk / -I /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/swift-linux-i686/./lib/swift/linux/i686 -warn-swift3-objc-inference-complete -module-cache-path /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/swift-linux-i686/./module-cache -module-link-name swiftCore -nostdimport -parse-stdlib -resource-dir /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/swift-linux-i686/./lib/swift -swift-version 3 -O -D INTERNAL_CHECKS_ENABLED -group-info-path /home/gigi/local/Source/apple/swift/stdlib/public/core/GroupInfo.json -enable-sil-ownership -Xllvm -sil-inline-generics -Xllvm -sil-partial-specialization -Xcc -D__SWIFT_CURRENT_DYLIB=swiftCore -parse-as-library -module-name Swift -o /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/swift-linux-i686/stdlib/public/core/linux/i686/Swift.o
1. While running pass #147 SILFunctionTransform "SIL alloc_stack Hoisting" on SILFunction "#_T0s7Float80V15_representationAB01_A14RepresentationVvg".
for getter for _representation at /home/gigi/local/Source/apple/swift/stdlib/public/core/FloatingPointTypes.swift.gyb:342:16
2. While converting type 'Float80' (declared at [/home/gigi/local/Source/apple/swift/stdlib/public/core/FloatingPointTypes.swift.gyb:74:8 - line:3662:1] RangeText="struct Float80 {
public // #testable
var _value: Builtin.FPIEEE80
/// Creates a value initialized to zero.
#_inlineable // FIXME(sil-serialize-all)
#_transparent
public init() {
let zero: Int64 = 0
self._value = Builtin.sitofp_Int64_FPIEEE80(zero._value)
}
#_inlineable // FIXME(sil-serialize-all)
#_transparent
public // #testable
init(_bits v: Builtin.FPIEEE80) {
self._value = v
}
}")
<unknown>:0: error: unable to execute command: Aborted
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)
ninja: build stopped: subcommand failed.
/home/gigi/local/Source/apple/swift/utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting
gigi#gigi-VirtualBox:~$ ]
Using ~/local/Source/apple/swift/utils/build-script --release to build.
I'm guessing the error has to do with this modification:
#elif defined(__linux__) && defined(__i386__)
typedef int __swift_ssize_t;
The official Swift project does not support 32bit architecture yet. There is an official ticket: Port Swift to Linux x86 32-bit
You will have more chance to get support on this ticket if you want to add this port yourself.

How to build Qt 5.2 on Solaris 10?

The Qt page does not list pre-compiled Qt 5 packages for Solaris. Searching around, it does not seem to be included in the popular package repository OpenCSW, either. Some google hits suggest that building Qt 5 under Solaris involves some work under Solaris 10.
Thus my question: How to build Qt 5.2 under Solaris 10?
Basically it is:
cd qt-everywhere-opensource-src-5.2.0
./configure -prefix $MY_PREFIX -opensource -confirm-license -nomake tests \
-R /opt/csw/lib/64 -R /opt/csw/X11/lib/64 -qt-xcb -platform solaris-g++-64 \
-verbose
gmake -j16
gmake -j16 install
plus some adjustments because Qt 5 does not seem to be used on
Solaris much, yet.
Adjustments
Obtain the source
wget http://download.qt-project.org/official_releases/qt/5.2/5.2.0/single/qt-everywhere-opensource-src-5.2.0.tar.gz
md5sum qt-everywhere-opensource-src-5.2.0.tar.gz
228b6384dfd7272de00fd8b2c144fecd qt-everywhere-opensource-src-5.2.0.tar.gz
If the system does not habe md5sum you can use openssl md5 filename instead.
Install dependencies
I recommend to use OpenCSW because we need some dependencies to build Qt. The most important ones are:
CSWlibxcbdevel
CSWlibicu-dev # soft-dependency
CSWgcc4g++
CSWgmake
I suggest to use GCC to compile Qt. I am not aware of any advantages using the C++ compiler from Solaris Studio. On the contrary, the level of C++/STL support of this compiler may be not sufficient for a lot of use cases.
Setup environment
Make sure that you environment is clean. That means that /opt/csw/bin comes first and no LD_LIBRAYR_PATH* variables are set.
To simplify things it is probably a good idea that some directories are removed from PATH. For example such that no cc, CC commands from a Solaris Studio installation are accidentally picked up (e.g. during the compile of a bundled 3rd party component.
Adjust the specs
The software under /usr/sfw is just too outdated. /opt/csw from OpenCSW is a better replacement. Then the X-Open version is not sufficient for some used system functions.
--- a/qtbase/mkspecs/solaris-g++-64/qmake.conf
+++ b/qtbase/mkspecs/solaris-g++-64/qmake.conf
## -35,7 +35,7 ## QMAKE_LEX = flex
QMAKE_LEXFLAGS =
QMAKE_YACC = yacc
QMAKE_YACCFLAGS = -d
-QMAKE_CFLAGS = -m64 -D_XOPEN_SOURCE=500 -D__EXTENSIONS__
+QMAKE_CFLAGS = -m64 -D_XOPEN_SOURCE=600 -D__EXTENSIONS__
QMAKE_CFLAGS_DEPS = -M
QMAKE_CFLAGS_WARN_ON = -Wall -W
QMAKE_CFLAGS_WARN_OFF = -w
## -58,8 +58,8 ## QMAKE_CXXFLAGS_STATIC_LIB = $$QMAKE_CFLAGS_STATIC_LIB
QMAKE_CXXFLAGS_YACC = $$QMAKE_CFLAGS_YACC
QMAKE_CXXFLAGS_THREAD = $$QMAKE_CFLAGS_THREAD
-QMAKE_INCDIR = /usr/sfw/include
-QMAKE_LIBDIR = /usr/sfw/lib/64
+QMAKE_INCDIR = /opt/csw/include /opt/csw/X11/include
+QMAKE_LIBDIR = /opt/csw/lib/64 /opt/csw/X11/lib/64
QMAKE_INCDIR_X11 = /usr/openwin/include
QMAKE_LIBDIR_X11 = /usr/openwin/lib/64
QMAKE_INCDIR_OPENGL = /usr/openwin/include
Fix the shell
Solaris comes with a /bin/sh that violates POSIX to an extend such
that Qt's configure scripts and even shell-code in qmake-generated
code fails.
POSIX does not specify that /bin/sh has to be conforming it just specifies that the system must have a conforming shell available 'somewhere'. On Solaris it is e.g. under /usr/xpg4/bin/sh. The portable way to get a conforming shell is to search for it in the directories returned by getconf CS_PATH ...
Anyways, my choice for Solaris is to just use /usr/bin/bash:
Anyways, my choice for Solaris is to just use /usr/bin/bash:
--- a/configure
+++ b/configure
## -1,4 +1,4 ##
-#! /bin/sh
+#!/usr/bin/bash
#############################################################################
##
## Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
--- a/qtbase/configure
+++ b/qtbase/configure
## -1,4 +1,4 ##
-#!/bin/sh
+#!/usr/bin/bash
#############################################################################
##
## Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
## -6892,7 +6892,7 ## fi'`
echo "$CONFIG_STATUS" | grep '\-confirm\-license' >/dev/null 2>&1 || CONFIG_STATUS="$CONFIG_STATUS -confirm-license"
[ -f "$outpath/config.status" ] && rm -f "$outpath/config.status"
- echo "#!/bin/sh" > "$outpath/config.status"
+ echo "#!/usr/bin/bash" > "$outpath/config.status"
[ -n "$PKG_CONFIG_SYSROOT_DIR" ] && \
echo "export PKG_CONFIG_SYSROOT_DIR=$PKG_CONFIG_SYSROOT_DIR" >> "$outpath/config.status"
[ -n "$PKG_CONFIG_LIBDIR" ] && \
--- a/qtbase/qmake/generators/makefile.cpp
+++ b/qtbase/qmake/generators/makefile.cpp
## -2306,6 +2306,10 ## MakefileGenerator::writeHeader(QTextStream &t)
if (ofile.lastIndexOf(Option::dir_sep) != -1)
ofile.remove(0, ofile.lastIndexOf(Option::dir_sep) +1);
t << "MAKEFILE = " << ofile << endl << endl;
+
+ t << "# custom mod because Solaris /bin/sh is such a standard-violating choice\n"
+ << "# - gs, 2013-12-23" << endl;
+ t << "SHELL = /usr/bin/bash" << endl << endl;
}
QList<MakefileGenerator::SubTarget*>
Fix the ICU test
Solaris 10 comes with an outdated libicu - which is missing features Qt 5 needs. Thus, we simply extend the icu-test. Then either no ICU-support is build or proper one in case we install a recent libicu e.g. via OpenCSW.
--- a/qtbase/config.tests/unix/icu/icu.cpp
+++ b/qtbase/config.tests/unix/icu/icu.cpp
## -43,6 +43,16 ##
#include <unicode/ucol.h>
#include <unicode/ustring.h>
+// for testing if ucal_clone is there (i.e. if we have libicu >= 4.0)
+#include <unicode/ucal.h>
+
+static UCalendar *ucp(UCalendar *i)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ UCalendar *r = ucal_clone(i, &status);
+ return r;
+}
+
int main(int, char **)
{
UErrorCode status = U_ZERO_ERROR;
## -50,5 +60,10 ## int main(int, char **)
if (U_FAILURE(status))
return 0;
ucol_close(collator);
+
+ UCalendar *cal = ucal_open(0, -1, "C", UCAL_GREGORIAN, &status);
+ UCalendar *x = ucp(cal);
+ ucal_close(x);
+
return 0;
}
Fix bundled pcre
Perhaps alternatively one can install a libpcre via OpenCSW.
--- a/qtbase/src/3rdparty/pcre/pcre_compile.c
+++ b/qtbase/src/3rdparty/pcre/pcre_compile.c
## -66,6 +66,8 ## COMPILE_PCREx macro will already be appropriately set. */
#endif
+#include <stdint.h>
+
/* Macro for setting individual bits in class bitmaps. */
#define SETBIT(a,b) a[(b)/8] |= (1 << ((b)&7))
Fix sha3
At least on Solaris 10/Sparc the functions fromBytesToWord and fromWordtoBytes are used by the code, thus:
--- a/qtbase/src/3rdparty/sha3/KeccakF-1600-opt64.c
+++ b/qtbase/src/3rdparty/sha3/KeccakF-1600-opt64.c
## -324,7 +324,7 ## static void KeccakPermutation(unsigned char *state)
KeccakPermutationOnWords((UINT64*)state);
}
-#if 0 // Unused in the Qt configuration
+#if 1 // Unused in the Qt configuration
static void fromBytesToWord(UINT64 *word, const UINT8 *bytes)
{
unsigned int i;
## -445,7 +445,7 ## static void KeccakAbsorb(unsigned char *state, const unsigned char *data, unsign
#endif
}
-#if 0 // Unused in the Qt configuration
+#if 1 // Unused in the Qt configuration
static void fromWordToBytes(UINT8 *bytes, const UINT64 word)
{
unsigned int i;
Include/type/usage fixes
The uname() function is activated via a CPP construct on Solaris
and is declared in that header:
--- a/qtbase/src/corelib/io/qfileselector.cpp
+++ b/qtbase/src/corelib/io/qfileselector.cpp
## -51,6 +51,8 ##
#include <QtCore/QLocale>
#include <QtCore/QDebug>
+#include <sys/utsname.h>
+
QT_BEGIN_NAMESPACE
//Environment variable to allow tooling full control of file selectors
Under Solaris parent is unused in that code-path and the code gets compiled with -Werror ...
--- a/qtbase/src/corelib/io/qfilesystemwatcher.cpp
+++ b/qtbase/src/corelib/io/qfilesystemwatcher.cpp
## -77,6 +77,7 ## QFileSystemWatcherEngine *QFileSystemWatcherPrivate::createNativeEngine(QObject
#elif defined(Q_OS_FREEBSD) || defined(Q_OS_MAC)
return QKqueueFileSystemWatcherEngine::create(parent);
#else
+ (void)parent;
return 0;
#endif
}
Under Solaris uid_t has an 'unexpected' sign (-> Werror). Casting it to ssize_t should be a portable and safe choice:
--- a/qtbase/src/corelib/io/qstandardpaths_unix.cpp
+++ b/qtbase/src/corelib/io/qstandardpaths_unix.cpp
## -132,7 +132,7 ## QString QStandardPaths::writableLocation(StandardLocation type)
}
// "The directory MUST be owned by the user"
QFileInfo fileInfo(xdgRuntimeDir);
- if (fileInfo.ownerId() != myUid) {
+ if (fileInfo.ownerId() != ssize_t(myUid)) {
qWarning("QStandardPaths: wrong ownership on runtime directory %s, %d instead of %d", qPrintable(xdgRuntimeDir),
fileInfo.ownerId(), myUid);
return QString();
Similar issue with threading code (Werror because of sign-mismatch in pointer cast). Casting to size_t should be a portable safe choice:
--- a/qtbase/src/corelib/thread/qthread_unix.cpp
+++ b/qtbase/src/corelib/thread/qthread_unix.cpp
## -231,7 +231,7 ## QThreadData *QThreadData::current()
}
data->deref();
data->isAdopted = true;
- data->threadId = (Qt::HANDLE)pthread_self();
+ data->threadId = (Qt::HANDLE)((size_t)pthread_self());
if (!QCoreApplicationPrivate::theMainThread)
QCoreApplicationPrivate::theMainThread = data->thread;
}
## -314,7 +314,7 ## void *QThreadPrivate::start(void *arg)
thr->d_func()->setPriority(QThread::Priority(thr->d_func()->priority & ~ThreadPriorityResetFlag));
}
- data->threadId = (Qt::HANDLE)pthread_self();
+ data->threadId = (Qt::HANDLE)((size_t)pthread_self());
set_thread_data(data);
data->ref();
## -393,7 +393,7 ## void QThreadPrivate::finish(void *arg)
Qt::HANDLE QThread::currentThreadId() Q_DECL_NOTHROW
{
// requires a C cast here otherwise we run into trouble on AIX
- return (Qt::HANDLE)pthread_self();
+ return (Qt::HANDLE)((size_t)pthread_self());
}
#if defined(QT_LINUXBASE) && !defined(_SC_NPROCESSORS_ONLN)
The struct in_addr has a struct as first attribute on Solaris, thus gives a warning with GCC when initializing with {0} - thus, yields an error during Qt-compile:
--- a/qtbase/src/network/socket/qnativesocketengine_unix.cpp
+++ b/qtbase/src/network/socket/qnativesocketengine_unix.cpp
## -63,6 +63,7 ##
#endif
#include <netinet/tcp.h>
+#include <string.h>
QT_BEGIN_NAMESPACE
## -737,7 +738,8 ## QNetworkInterface QNativeSocketEnginePrivate::nativeMulticastInterface() const
return QNetworkInterface::interfaceFromIndex(v);
}
- struct in_addr v = { 0 };
+ struct in_addr v;
+ memset(&v, 0, sizeof(struct in_addr));
QT_SOCKOPTLEN_T sizeofv = sizeof(v);
if (::getsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF, &v, &sizeofv) == -1)
return QNetworkInterface();
The header comment of X11/Xutil.h lists X11/Xutil.h as dependency, and indeed, without that include some declarations are missing under Solaris.
--- a/qtbase/src/plugins/platforms/xcb/qxcbmime.cpp
+++ b/qtbase/src/plugins/platforms/xcb/qxcbmime.cpp
## -46,6 +46,7 ##
#include <QtCore/QBuffer>
#include <qdebug.h>
+#include <X11/Xlib.h>
#include <X11/Xutil.h>
#undef XCB_ATOM_STRING
The X11/extensions/XIproto.h is not C++-safe under Solaris. That means it contains struct members names class. Fortunately, the header does not seem to be used in that code.
--- a/qtbase/src/plugins/platforms/xcb/qxcbxsettings.cpp
+++ b/qtbase/src/plugins/platforms/xcb/qxcbxsettings.cpp
## -43,7 +43,7 ##
#include <QtCore/QByteArray>
-#include <X11/extensions/XIproto.h>
+//#include <X11/extensions/XIproto.h>
QT_BEGIN_NAMESPACE
/* Implementation of http://standards.freedesktop.org/xsettings-spec/xsettings-0.5.html */
The pow() function has some overloads as specified in the C++ standard which introduce ambiguities under Solaris. Fixing the types like this should be portable and safe:
--- a/qtdeclarative/src/qml/jsruntime/qv4globalobject.cpp
+++ b/qtdeclarative/src/qml/jsruntime/qv4globalobject.cpp
## -534,7 +534,7 ## ReturnedValue GlobalFunctions::method_parseInt(CallContext *ctx)
}
if (overflow) {
- double result = (double) v_overflow * pow(R, overflow_digit_count);
+ double result = (double) v_overflow * pow(double(R), int(overflow_digit_count));
result += v;
return Encode(sign * result);
} else {
Under Solaris, alloca needs another header:
--- a/qtdeclarative/src/qml/jsruntime/qv4stringobject.cpp
+++ b/qtdeclarative/src/qml/jsruntime/qv4stringobject.cpp
## -73,6 +73,11 ##
# include <windows.h>
#endif
+
+#if OS(SOLARIS)
+#include <alloca.h>
+#endif
+
using namespace QV4;
DEFINE_MANAGED_VTABLE(StringObject);
Fix deep mkdir
Qt does a 'deep' mkdir() (e.g. something like mkdir -p for e.g. creating a directory hierarchy, e.g. ~/.config/company/product. The Qt 5.2 algorithm may abort too soon on Solaris if an existing directory is located inside a non-writable NFS mounted parent - because in that case Solaris returns EACCESS instead of EEXIST.
--- a/qtbase/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/qtbase/src/corelib/io/qfilesystemengine_unix.cpp
## -579,6 +579,11 ## bool QFileSystemEngine::createDirectory(const QFileSystemEntry &entry, bool crea
// on the QNet mountpoint returns successfully and reports S_IFDIR.
|| errno == ENOENT
#endif
+#if defined(Q_OS_SOLARIS)
+ // On Solaris 10, mkdir returns EACCESS on a directory which exists
+ // inside an NFS mount ...
+ || errno == EACCES
+#endif
) {
QT_STATBUF st;
if (QT_STAT(chunk.constData(), &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
Temporary files
Solaris also does not have mkdtemp():
--- a/qtbase/src/corelib/io/qtemporarydir.cpp
+++ b/qtbase/src/corelib/io/qtemporarydir.cpp
## -52,7 +52,7 ##
#endif
#include <stdlib.h> // mkdtemp
-#if defined(Q_OS_QNX) || defined(Q_OS_WIN) || defined(Q_OS_ANDROID)
+#if defined(Q_OS_QNX) || defined(Q_OS_WIN) || defined(Q_OS_ANDROID) || defined(Q_OS_SOLARIS)
#include <private/qfilesystemengine_p.h>
#endif
## -96,7 +96,7 ## static QString defaultTemplateName()
static char *q_mkdtemp(char *templateName)
{
-#if defined(Q_OS_QNX ) || defined(Q_OS_WIN) || defined(Q_OS_ANDROID)
+#if defined(Q_OS_QNX ) || defined(Q_OS_WIN) || defined(Q_OS_ANDROID) || defined(Q_OS_SOLARIS)
static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
const size_t length = strlen(templateName);
Pthreads
Solaris does not have pthread_get_stacksize_np (the _np suffix stands for non-portable).
Solaris has another function for getting stack-address/size values. My attempt:
--- a/qtdeclarative/src/qml/jsruntime/qv4engine.cpp
+++ b/qtdeclarative/src/qml/jsruntime/qv4engine.cpp
## -73,6 +73,11 ##
#include "qv4isel_moth_p.h"
#if USE(PTHREADS)
+
+#if OS(SOLARIS)
+#include <thread.h>
+#endif
+
# include <pthread.h>
#endif
## -103,6 +108,11 ## quintptr getStackLimit()
} else
size = pthread_get_stacksize_np(thread_self);
stackLimit -= size;
+# elif OS(SOLARIS)
+ stack_t ss;
+ int r = thr_stksegment(&ss);
+ (void)r;
+ stackLimit = reinterpret_cast<quintptr>(ss.ss_sp);
# else
void* stackBottom = 0;
pthread_attr_t attr;
--- a/qtdeclarative/src/qml/jsruntime/qv4mm.cpp
+++ b/qtdeclarative/src/qml/jsruntime/qv4mm.cpp
## -67,6 +67,11 ##
#include <sys/storage.h> // __tls()
#endif
+#if OS(SOLARIS)
+#include <thread.h>
+#include <pthread.h>
+#endif
+
QT_BEGIN_NAMESPACE
using namespace QV4;
## -218,6 +223,11 ## MemoryManager::MemoryManager()
# if OS(DARWIN)
void *st = pthread_get_stackaddr_np(pthread_self());
m_d->stackTop = static_cast<quintptr *>(st);
+# elif OS(SOLARIS)
+ stack_t ss;
+ int r = thr_stksegment(&ss);
+ (void)r;
+ m_d->stackTop = static_cast<quintptr *>(ss.ss_sp) + ss.ss_size/sizeof(quintptr);
# else
void* stackBottom = 0;
pthread_attr_t attr;
I recommend a careful review of that code because my Qt-code does not use that Qt-module, thus, I did not test it much.
XKB extension
Qt 5 seems to heavily rely on the XKB extension. It seems that you can't build Qt 5 without XKB support. It comes bundled with xkbcommon.
First, make sure that it finds the right XKB database. Otherwise keyboard input does not work at all in your Qt programs!
Solaris does not have the default value /usr/share/X11/xkb. It has instead:
/usr/X11/lib/X11/xkb
/usr/openwin/lib/X11/xkb
But I havn't had luck with those - xkbcommon simply could not find any components with those.
I ended up with copying /usr/share/X11/xkb from a cygwin distribution to a custom path and configuring that as XKB database.
Whatever XKB you choose you have to configure it:
--- a/qtbase/src/3rdparty/xkbcommon.pri
+++ b/qtbase/src/3rdparty/xkbcommon.pri
## -1,7 +1,12 ##
QMAKE_CFLAGS += -std=gnu99 -w
INCLUDEPATH += $$PWD/xkbcommon $$PWD/xkbcommon/src $$PWD/xkbcommon/src/xkbcomp
+solaris-g++-64 {
+DEFINES += DFLT_XKB_CONFIG_ROOT='\\"/MY/XKB/CHOICE\\"'
+} else {
DEFINES += DFLT_XKB_CONFIG_ROOT='\\"/usr/share/X11/xkb\\"'
+}
### RMLVO names can be overwritten with environmental variables (See libxkbcommon documentation)
DEFINES += DEFAULT_XKB_RULES='\\"evdev\\"'
For testing it also make sense to check for NULL values in error message parameters:
--- a/qtbase/src/3rdparty/xkbcommon/src/xkbcomp/xkbcomp.c
+++ b/qtbase/src/3rdparty/xkbcommon/src/xkbcomp/xkbcomp.c
## -68,8 +68,11 ## text_v1_keymap_new_from_names(struct xkb_keymap *keymap,
log_err(keymap->ctx,
"Couldn't look up rules '%s', model '%s', layout '%s', "
"variant '%s', options '%s'\n",
- rmlvo->rules, rmlvo->model, rmlvo->layout, rmlvo->variant,
- rmlvo->options);
+ rmlvo->rules, rmlvo->model,
+ rmlvo->layout ? rmlvo->layout : "(NULL)",
+ rmlvo->variant ? rmlvo->variant : "(NULL)",
+ rmlvo->options ? rmlvo->options : "(NULL)"
+ );
return false;
}
There is also the possibility that your XServer does not even support the XKB extension. Again, I don't know if Qt 5 can be configured with disabled-XKB-support under X.
You can check your X-server like this:
xprop -root | grep xkb
Or call a random xkb-program, e.g.:
xkbvleds
Such call should not result in an error like:
Fatal Error: Server doesn't support a compatible XKB
In case your XServer does not have XKB - Qt programs are likely to segfault. Qt does not seem to really check for XKB support. It does not seem to have a fallback mechanism when XKB is not usable.
Examples
Some examples fail because of module quick not being found:
--- a/qtconnectivity/examples/bluetooth/scanner/scanner.pro
+++ b/qtconnectivity/examples/bluetooth/scanner/scanner.pro
## -1,4 +1,4 ##
-QT = core bluetooth quick
+QT = core bluetooth # quick
SOURCES += qmlscanner.cpp
TARGET = qml_scanner
diff --git a/qtconnectivity/examples/nfc/poster/poster.pro b/qtconnectivity/examples/nfc/poster/poster.pro
index d108b2a..d0d0659 100644
--- a/qtconnectivity/examples/nfc/poster/poster.pro
+++ b/qtconnectivity/examples/nfc/poster/poster.pro
## -1,4 +1,4 ##
-QT += qml quick network nfc widgets
+QT += qml network nfc widgets # quick
SOURCES += \
qmlposter.cpp
They are also built without.
make install
A gmake install surprisingly triggers the compilation of several modules not yet compiled. Thus it make sense to execute it in parallel:
$ gmake -j16 install
(assuming that your system has a sufficient number of cores)
QtHelp
The bundled QtHelp module is not build/installed with the main compile/install steps.
To fix that:
cd qttools
PATH=$MY_PREFIX/bin:$PATH qmake
gmake
gmake install
Open issues
when using a remote Cygwin-X connection some colors are weird - e.g. the standard widget-gray is some light-light-blue - any ideas where to start to look for that?
QtSVG is successfully built but displaying a small SVG (e.g. inside a QLabel) hangs the dialog - a truss -u : shows function calls inside libm/QtWidget - perhaps the system is just way too slow and/or some code-path is not optimized on Solaris/in combination with a X-forwarding over ssh
a Qt-Program prints on startup: Qt Warning: Could not find a location of the system's Compose files. Consider setting the QTCOMPOSE environment variable. - no idea what feature this is about
Conclusion
With those adjustments 'normal' Qt programs (without QtSvg) compile
and run fine under Solaris 10.