Add glibc as a library

This commit is contained in:
Paul Gey
2026-05-16 20:28:18 +02:00
parent 9e60f1a039
commit 95996cb424
4 changed files with 53 additions and 1 deletions
+11
View File
@@ -4505,6 +4505,17 @@ libs.cs50.versions.910.path=/opt/compiler-explorer/libs/cs50/9.1.0/include
libs.cs50.versions.910.libpath=/opt/compiler-explorer/libs/cs50/9.1.0/x86_64/lib:/opt/compiler-explorer/libs/cs50/9.1.0/x86/lib
libs.cs50.versions.910.liblink=cs50
libs.glibc.name=glibc
libs.glibc.versions=216:241
libs.glibc.versions.216.version=2.16
libs.glibc.versions.216.libpath=/opt/compiler-explorer/libs/glibc/glibc-2.16/usr/lib64:/opt/compiler-explorer/libs/glibc/glibc-2.16/lib64
libs.glibc.versions.216.sysroot=/opt/compiler-explorer/libs/glibc/glibc-2.16
libs.glibc.versions.216.dynamicLinker=/opt/compiler-explorer/libs/glibc/glibc-2.16/lib64/ld-linux-x86-64-so.2
libs.glibc.versions.241.version=2.41
libs.glibc.versions.241.libpath=/opt/compiler-explorer/libs/glibc/glibc-2.41/usr/lib64:/opt/compiler-explorer/libs/glibc/glibc-2.41/lib64
libs.glibc.versions.241.sysroot=/opt/compiler-explorer/libs/glibc/glibc-2.41
libs.glibc.versions.241.dynamicLinker=/opt/compiler-explorer/libs/glibc/glibc-2.41/lib64/ld-linux-x86-64-so.2
libs.hedley.name=hedley
libs.hedley.description=A C/C++ header to help move ifdefs out of your code
libs.hedley.versions=v12
+23
View File
@@ -995,6 +995,20 @@ export class BaseCompiler {
});
}
getSharedLibraryDynamicLinker(libraries: SelectedLibraryVersion[], dirPath?: string): string[] {
return libraries.flatMap(selectedLib => {
const foundVersion = this.findLibVersion(selectedLib);
if (!foundVersion) return [];
if (foundVersion.dynamicLinker === undefined) return [];
const paths = [foundVersion.dynamicLinker];
if (this.buildenvsetup && !this.buildenvsetup.extractAllToRoot && dirPath) {
paths.push(path.join(dirPath, selectedLib.id, 'lib'));
}
return paths;
});
}
getSharedLibraryBinPaths(libraries: SelectedLibraryVersion[], dirPath?: string): string[] {
return libraries.flatMap(selectedLib => {
const foundVersion = this.findLibVersion(selectedLib);
@@ -1016,6 +1030,8 @@ export class BaseCompiler {
): string[] {
const pathFlag = this.compiler.rpathFlag || this.defaultRpathFlag;
const libPathFlag = this.compiler.libpathFlag || '-L';
// TODO: make configurable
const dynamicLinkerFlag = '-Wl,--dynamic-linker=';
let toolchainLibraryPaths: string[] = [];
if (toolchainPath) {
@@ -1033,6 +1049,7 @@ export class BaseCompiler {
toolchainLibraryPaths.map(path => pathFlag + path),
this.getSharedLibraryPaths(libraries, dirPath).map(path => pathFlag + path),
this.getSharedLibraryPaths(libraries, dirPath).map(path => libPathFlag + path),
this.getSharedLibraryDynamicLinker(libraries, dirPath).map(path => dynamicLinkerFlag + path),
);
}
@@ -1080,6 +1097,9 @@ export class BaseCompiler {
getIncludeArguments(libraries: SelectedLibraryVersion[], dirPath: string): string[] {
const includeFlag = this.compiler.includeFlag || '-I';
// TODO: make configurable
const sysrootFlag = '--sysroot=';
return libraries.flatMap(selectedLib => {
const foundVersion = this.findLibVersion(selectedLib);
if (!foundVersion) return [];
@@ -1089,6 +1109,9 @@ export class BaseCompiler {
const includePath = path.join(dirPath, selectedLib.id, 'include');
paths.push(includeFlag + includePath);
}
if (foundVersion.sysroot) {
paths.push(sysrootFlag + foundVersion.sysroot);
}
return paths;
});
}
+17 -1
View File
@@ -59,6 +59,8 @@ export type VersionInfo = {
options: string[];
hidden: boolean;
packagedheaders?: boolean;
sysroot?: string;
dynamicLinker?: string;
$order?: number;
};
export type OptionsHandlerLibrary = {
@@ -357,10 +359,19 @@ export class ClientOptionsHandler implements ClientOptionsSource {
versionObject.lookupname = libraries[lang][lib].lookupname;
}
const sysroot = this.compilerProps<string>(lang, libVersionName + '.sysroot');
if (sysroot !== undefined) {
versionObject.sysroot = sysroot;
}
const includes = this.compilerProps<string>(lang, libVersionName + '.path');
if (includes) {
versionObject.path = includes.split(path.delimiter);
} else if (version !== 'autodetect' && !versionObject.packagedheaders) {
} else if (
version !== 'autodetect' &&
!versionObject.packagedheaders &&
!versionObject.sysroot
) {
logger.warn(`Library ${lib} ${version} (${lang}) has no include paths`);
}
@@ -380,6 +391,11 @@ export class ClientOptionsHandler implements ClientOptionsSource {
libraries[lang][lib].packagedheaders,
);
const dynamicLinker = this.compilerProps<string>(lang, libVersionName + '.dynamicLinker');
if (dynamicLinker !== undefined) {
versionObject.dynamicLinker = dynamicLinker;
}
libraries[lang][lib].versions[version] = versionObject;
}
} else {
+2
View File
@@ -9,6 +9,8 @@ export type LibraryVersion = {
path: string[];
options: string[];
packagedheaders?: boolean;
sysroot?: string;
dynamicLinker?: string;
};
export type Library = {